library(ggplot2)
library(dplyr)
data("diamonds", package = "ggplot2")

Introduction

This report explores prices and characteristics of the 53,940 diamonds in the diamonds dataset included with ggplot2. The analysis uses plots and descriptive summaries to identify patterns. These are descriptive comparisons; they do not establish cause and effect or describe current market prices.

Q1. Price histogram

ggplot(diamonds, aes(x = price)) +
  geom_histogram(binwidth = 500, fill = "steelblue", color = "white") +
  labs(
    title = "Distribution of Diamond Prices",
    x = "Price (US dollars)",
    y = "Number of diamonds"
  ) +
  theme(
    plot.title = element_text(hjust = 0.5)
  )

Explanation: The price distribution is strongly right-skewed. Most diamonds are concentrated at the lower end of the price range, particularly below about $5,000, while a smaller number of diamonds have much higher prices, creating a long right tail.And the histogram is appropriate because price is a numerical variable and the plot shows how observations are distributed across price intervals. . ## Q2. Price boxplots by cut

ggplot(diamonds, aes(x = price, y = cut)) +
  geom_boxplot(fill = "steelblue", outlier.alpha = .25) +
  labs(
      title = "Diamond Prices by Cut Category",
         x = "Price (US dollars)",
         y = "Cut quality"
  ) +
   theme(
          plot.title = element_text(hjust = 0.5)
   )

Explanation: The median price for Fair-cut diamonds is about $3,282, compared with about $1,810 for Ideal-cut diamonds. Premium diamonds have a wider middle spread (IQR about $5,250) than Ideal diamonds (IQR about $3,801). These boxplots describe price differences, but they do not show that better cut quality causes higher prices. Price may also vary with carat, color, clarity, and other characteristics.

Q3. Carat and price, colored by cut

ggplot(diamonds, aes(x = carat, y = price)) +
  geom_point(aes(color = cut), alpha = 0.35) +
  geom_smooth(method = "lm", se = FALSE, color = "black") +
  labs(
    title = "Relationship Between Diamonds' Weight and Price",
    x = "Weight (carats)",
    y = "Price (US dollars)",
    color = "Cut quality"
  ) +
  theme(
    plot.title = element_text(hjust = .50)
  )

Explanation: There is a clear positive relationship: larger diamonds generally have higher prices. The cut categories overlap substantially, so carat and price values are not separated into distinct groups by cut. Mapping color = cut inside aes() assigns colors according to each observation’s cut category and creates a legend. Setting a color outside aes(), such as color = "black", gives every point or line the same fixed color. The black line is one overall linear visual trend across all diamonds, not a separate line for each cut.

Q4. Carat and price, faceted by cut

ggplot(diamonds, aes(x = carat, y = price)) +
  geom_point(alpha = 0.30, color = "steelblue") +
  facet_wrap(~ cut) +
  labs(
    title = "Carat and Price Within Each Cut Category",
    x = "Weight (carats)",
    y = "Price (US dollars)"
  ) +
  theme(
    plot.title = element_text(hjust = 0.50)
  )

Explanation: The positive relationship between carat and price appears within all five cut categories. Faceting separates the observations into panels, making it easier to inspect each category without the colors and points overlapping in one panel. The panels use common axis scales, so the position and spread of points can be compared fairly across categories; independently scaled panels could make differences look larger or smaller than they are.

Q5a. Counts by cut and color

ggplot(diamonds, aes(x = cut, fill = color)) +
  geom_bar(position = "dodge") +
  labs(
    title = "Number of Diamonds by Cut and Color Grade",
    x = "Cut quality",
    y = "Number of diamonds",
    fill = "Color grade"
  ) +
  theme(
    plot.title = element_text(hjust = 0.50)
  )

Explanation: The side-by-side bar chart shows counts. Ideal has the largest total number of diamonds, while Fair has the smallest. The count chart answers “how many?”

Q5b. Proportions by cut and color

ggplot(diamonds, aes(x = cut, fill = color)) +
  geom_bar(position = "fill") +
  labs(
    title = "Color-Grade Composition Within Each Cut Category",
    x = "Cut quality",
    y = "Proportion of diamonds",
    fill = "Color grade"
  ) +
  scale_y_continuous(labels = scales::label_percent()) +
  theme(
    plot.title = element_text(hjust = 0.50)
  )

Explanation: The proportional chart scales each cut category to 100%, so it is more useful for comparing color composition when the cut categories have different sample sizes. Each segment’s denominator is the total number of diamonds in that cut category. For example, G-color diamonds make up about 22.7% of Ideal diamonds and about 21.2% of Premium diamonds. The proportional chart answers “what share?”

Q6. Summary table and mean-price bar chart.

cut_summary <- diamonds %>%
  group_by(cut) %>%
  summarise(
    number_of_diamonds = n(),
    mean_price = mean(price),
    median_price = median(price),
    .groups = "drop"
  )

knitr::kable(
  cut_summary,
  digits = 2,
  col.names = c("Cut category", "Number of diamonds",
                "Mean price (US dollars)", "Median price (US dollars)"),
  caption = "Diamond count and price summaries by cut category"
) 
Diamond count and price summaries by cut category
Cut category Number of diamonds Mean price (US dollars) Median price (US dollars)
Fair 1610 4358.76 3282.0
Good 4906 3928.86 3050.5
Very Good 12082 3981.76 2648.0
Premium 13791 4584.26 3185.0
Ideal 21551 3457.54 1810.0
ggplot(cut_summary, aes(x = cut, y = mean_price)) +
  geom_col(fill = "steelblue") +
  labs(
    title = "Mean Diamond Price by Cut Category",
    x = "Cut quality",
    y = "Mean price (US dollars)"
  ) +
    theme(
    plot.title = element_text(hjust = 0.50)
)

Explanation: The default geom_bar() counts observations in each category, so it is not appropriate for values that have already been calculated. geom_col() uses the supplied mean price values as bar heights. In the Premium category, the mean price is about $4,584 while the median is about $3,185. The mean being higher than the median is consistent with a right-skewed price distribution: some high-priced diamonds pull the mean upward.

Q7. Additional visualization question : How does diamond weight (carats) vary across cut categories?

ggplot(diamonds, aes(x = cut, y = carat)) +
  geom_boxplot(fill = "tan", outlier.alpha = 0.20) +
  labs(
    title = "Diamond Weight by Cut Category",
    x = "Cut quality",
    y = "Weight (carats)"
  ) +
     theme(
    plot.title = element_text(hjust = 0.50)
)

Explanation: This boxplot compares diamond weight across the cut categories. The line inside each box shows the median weight. In this dataset, the median is about 1.00 carat for Fair diamonds and 0.54 carat for Ideal diamonds. This means the typical diamond in the Fair group is heavier than the typical diamond in the Ideal group in this sample. However, this plot only compares the groups; it does not explain why their weights are different.

Conclusion

The plots show that diamond prices are right-skewed, price generally increases with carat weight, and price and weight distributions vary across cut categories. Count and proportion charts answer different questions: counts compare group sizes, while proportions compare the composition of each group. These findings describe this dataset only and should not be interpreted as causal effects or as statements about current diamond-market prices.