Q1

ggplot(dim, aes(carat, price)) + 
geom_point(aes(fill = as.character(clarity)),
             color = "black",
             alpha = 0.3,
             shape = 21,
             size = 1.5) +
  labs(title = "Scatterplot of Diamond Prices", x = "Diamond Carats", y = "Diamond Price") +
  scale_y_continuous(labels = scales::dollar_format(prefix = "$"))

Q2 (2 points)

The previous graph looks cluttered. So you decided to use facets instead. Recreate the following graph:

ggplot(dim, aes(carat,price)) +
  geom_point(aes(fill = as.character(clarity)),
             color = "black",
             alpha = 0.3,
             shape = 21,
             size = 1.5,
             show.legend = FALSE) +
  labs(title = "Scatterplot of Diamond Prices", x = "Diamond Carats", y = "Diamond Price") + 
  scale_y_continuous(labels = scales::dollar_format(prefix = "$")) +
  facet_wrap(nrow = 2, ncol = 4, ~ clarity)

##Q3 (5 points)

ggplot(dim, aes(table, price)) + 
  geom_smooth(method = "lm",
              formula = y ~ x,
              alpha = 0.3,
              color = "red",
              linetype = "dashed",
              fill = "gray",
              show.legend = FALSE) + 
  scale_x_continuous(breaks = seq(0,100, by = 25),
                     limits = c(0,100)) + 
  scale_y_continuous(breaks = seq(0,10000, by = 5000)) +
  labs(x = "Table", y = "Price")

ggplot(dim, aes(depth, price)) + 
  geom_smooth(method = "lm",
              formula = y ~ x,
              alpha = 0.3,
              color = "white",
              linetype = "dotdash",
              fill = "gray",
              show.legend = FALSE) + 
  scale_x_continuous(breaks = seq(0,80, by = 10),
                     limits = c(0,80)) + 
  scale_y_continuous(breaks = seq(3000,5000, by = 500)) +
  labs(x = "Depth", y = "Price")

Q4 (5 points)

Recreate each of the following graphs for data exploration:

ggplot(dim, aes(x*y*z, price)) +
  geom_point(aes(color = cut)) +
  scale_fill_manual(values = colorpal1) + 
  scale_color_manual(values = colorpal1) +
  labs(x = "x * y * z", y = "price")

ggplot(dim, aes(price)) +
  geom_histogram(bins = 75, fill = "gray40", color = "white") +
  scale_x_continuous(labels = scales::dollar_format(prefix = "$"),
                     breaks = seq(0,15000, by = 5000)) +
  scale_y_continuous(labels = scales::comma_format(),
                     breaks = seq(0,7000, by = 2000))

ggplot(dim, aes(clarity)) +
  geom_bar(fill = colorpal2 ,color = "red") +
  scale_y_continuous(breaks = seq(0,10000, by = 5000))

ggplot(dim, aes(cut, depth)) + 
  geom_violin(color = "blue") +
  geom_jitter(color = "red",  alpha = 0.03)

ggplot(dim, aes(x, price)) +
  geom_smooth(method = "lm",
              color = "green",
              show.legend = FALSE) + 
  geom_smooth(fill = "white",
              show.legend = FALSE)