Assignment:

1. Use the diamonds dataset (part of ggplot2 package), create a visualization to explore the relationship between carat and price conditioned on (diamond) color.

  • carat: number (continuous)
  • price: integer (discrete)
  • color: ordinal factor (discrete)
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.5.2
ggplot(diamonds, aes(price, carat, color = color)) +
  geom_point()

ggplot(diamonds, aes(carat, price, color = color)) +
  geom_point() +
  geom_smooth()
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'

2. Create a visualization to explore the distribution of price conditioned on (diamond) cut.

ggplot(diamonds, aes(cut, price, color = color)) +
  geom_boxplot()

You should explore various visualization options, and make/select/present a visualization that you think is most effective.

ggplot(diamonds, aes(price, fill = cut, color = cut)) + 
  geom_density(na.rm = TRUE)

ggplot(diamonds, aes(carat, fill = cut, color = cut)) + 
  geom_density(na.rm = TRUE)