Code

library(ggplot2)
library(trelliscopejs)
library(dplyr)
ddata <- read.csv("diamonds.csv")
ddata <- ddata %>%
  group_by(color) %>%
  mutate(R2 = summary(lm(price ~ carat))$r.squared, price_per_carat = price/carat)
ggplot(ddata, aes(x=carat, y=price)) +
  geom_point()+
facet_trelliscope(~ color, path = ".", self_contained = TRUE)

Discussion

In the assignment, Diamonds dataset is used that contains the prices and other attributes of almost 54,000 diamonds. The attributes of interest are price (in USD), carat(weight of diamond), and color (D,E,F,G,H,I,J). I am interested in knowing (i) if there is proportional relationship between price and carat, & (ii) how does diamond prices vary with its color.

To investigate, a faceted scatter plot of price vs carat is created using the trelliscopejs package. Two cognistic measures were added to the plot. The columns for R squared value for each individual plot (or diamond color) and price/carat for every diamond were added to the data table. The shapes of carat vs price faceted scatter plots and R2 value greater than 0.8 for each individual scatter plot strongly suggest that price and carat are directly proportional. The averages of price/carat for each diamond color subset suggest that there is no definite price trend for diamond color from D to J.

Initially, I was interested in knowing pricing trend for diamonds based on color and cut attributes. This resulted in 35 individual scatter plots and I was unable to get an insight.Then, I shifted my focus towards color only.