library(tidyverse)
library(openintro)
loans <- select(loans_full_schema, loan_amount, interest_rate, term, 
         grade, state, annual_income, homeownership, debt_to_income)

Lab Exercise

Create a density plot of interest_rate in loans data with

ggplot(loans, aes(x = interest_rate)) +
  geom_density(linewidth = 1.5, fill = 'green', linetype = 'dashed', color = 'blue')

Lab Exercise

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(mpg) +
  geom_point(aes(x = cty, y = hwy)) +
  labs(title = "Fuel Economy Data",
       x = "Miles per gallon in city",
       y = "Miles per gallon in highway") +
  theme(plot.title = element_text(size = rel(2), colour = "blue"),
        axis.title = element_text(size = rel(1.5)),
        aspect.ratio = 1)

Lab Homework

  1. Create a graph based on the diamonds data set with the following requirements:
ggplot(diamonds) +
  geom_point(aes(x = carat, y = price, color = clarity)) +
  facet_grid(cut ~ color) +
  scale_y_continuous(labels = scales::dollar) +
  labs(title = "Carat vs Price",
       x = "Carat",
       y = "Price (USD)") +
  theme(plot.title = element_text(size = rel(2), colour = "blue"),
        axis.title = element_text(size = rel(1.5)),
        aspect.ratio = 1)

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

Answer: I think the plot is quite informative since it shows the trend: as carat increases, price also increases. But the issue is it has too many points so it is kinda hard to read.