Part I: Lab Homework

Finish all Lab Exercises



Lab 1

Create a density plot of interest_rate in loans data with:

  1. color to be blue
  2. fill to be green
  3. linetype to be dashed
  4. linewidth to be 1.5

ggplot(data = loans, mapping = aes(x = interest_rate)) +
  geom_density(color = "blue", fill = "green", linetype = "dashed", linewidth = 1.5) +
  labs(x = "Interest Rate (%)", 
       y = "Density", 
       title = "The Interest Rate from Lending Club Data") +
  theme(plot.title = element_text(hjust = 0.5))




Lab 2

Do a simple graph ggplot(mpg) + geom_point(aes(x = cty, y = hwy)), make the following customization of your graph:

  1. Make a title of “Fuel Economy Data.”
  2. Make your x label of “miles per gallon in city”, and a y label of “miles per gallon in highway”.
  3. Make your title 2 times larger and in color blue
  4. Make your labels in x and y 1.5 times larger
  5. Change the aspect ratio of your graph to be 1 to make your graph square. Find how to do this by yourself with the assistance of help documentation.


ggplot(data = mpg) +
  geom_point(mapping = aes (x = cty, y = hwy), color = "orange2", size = 3) +
  labs(title = "Fuel Economy Data", 
       x = "miles per gallon in city", 
       y = "miles per gallon in highway") +
  theme(plot.title = element_text(hjust = 0.5, size = rel(2), color = "blue"),
        axis.title = element_text(hjust = 0.5, size = rel(1.5))) 



Part II: Create a Graph Based on the Diamonds Data Set with the Following Requirements:



-A grid of scatter plots with x being carat and y being price.
-In each plot, use different colors for different clarity quality.
-For the grid of subplots, the x-axis should refer to different cut quality, and the y-axis referring to different diamond color.
-The scale of y-axis should be in the format like $5,000 etc.


ggplot(data = diamonds) +
  geom_point(mapping = aes(x = carat, y = price, color = clarity)) +
  facet_grid(color ~ cut) +
  xlim(0, 5) + ylim(0, 20000) +
  labs(title = "Diamond Quality Data by Its Clarity and Cut",
       x = "Weight of the Diamonds (Carat)",
       y = "Price of the Diamonds (USD)") +
  theme(plot.title = element_text(hjust = 0.5,  size = rel(2.3), margin = margin(20, 25, 20, 20), color = "blue4"),
        axis.title = element_text(size = rel(1.5), color = "green4"),
        axis.title.x = element_text(size = rel(1.1), margin = margin(15, 5, 5, 5)),
        axis.title.y = element_text(size = rel(1.1), margin = margin(5, 10, 15, 5)),
        axis.text = element_text(size = rel(1.2), color = "green4")) +
  scale_y_continuous(labels = scales::dollar) 


Do you think the plot is informative? Provide your opinion.

Answer: Yes, this provides valuable information about the overall distribution of diamond quality and price ranges for different grades. Additionally, if you have a specific diamond and want to assess whether you purchased it at a fair price, this plot can be useful, as it allows for quick analysis.

On the other hand, it may feel overwhelming to interpret at a glance for those looking to study the relationships between variables. To make the data more accessible, I would present it through multiple simpler plots rather than condensing everything into a single table.




Submit your answer in a single pdf or html knitted from a R markdown file. Submit your R markdown file as well.