Directions

The objective of this assignment is to complete and explain basic plots before moving on to more complicated ways to graph data.

Each question is worth 5 points.

To submit this homework you will create the document in Rstudio, using the knitr package (button included in Rstudio) and then submit the document to your Rpubs account. Once uploaded you will submit the link to that document on Canvas. Please make sure that this link is hyper linked and that I can see the visualization and the code required to create it (echo=TRUE).

Questions

  1. For The following questions use the Marriage data set from the mosaicData package.
data1 <- mosaicData::Marriage

ggplot(data1, aes(x = college)) + 
  geom_histogram(binwidth = 0.5,position = "dodge")+
  facet_wrap(~person)+
  labs(title = 'Histogram of number of people who have different college years (Bride vs Groom)',
     x = 'college year', y = 'number of people') 
## Warning: Removed 10 rows containing non-finite values (`stat_bin()`).

#The graph above shows the number of people who have different college years, and compares Bride and Groom.

ggplot(data1, aes(x = college,y=age)) + 
  geom_point(aes(shape = prevconc,color=race), size = 1)+
  facet_wrap(~person)+
  labs(title = 'Age vs college year in different race and prevconc',
     x = 'college year', y = 'age') 
## Warning: Removed 54 rows containing missing values (`geom_point()`).

Your objective for the next four questions will be write the code necessary to exactly recreate the provided graphics.

  1. Boxplot Visualization

This boxplot was built using the mpg dataset. Notice the changes in axis labels.

data2 <- mpg

ggplot(data2, aes(x = manufacturer, y = hwy)) +
  geom_boxplot() +
  coord_flip() +
  theme_classic() + 
  labs(x = 'Manufacturer',
    y = 'Highway miles per gallon')

  1. Stacked Density Plot

This graphic is built with the diamonds dataset in the ggplot2 package.

data3 <- diamonds

ggplot(data3, aes(price, fill= cut)) +
  geom_density(alpha = 0.3, size = 0.1) +
  labs(title = "Diamond Price Density",
       x="Price",y = "Density")

  1. Sideways bar plot

This graphic uses the penguins dataset and shows the counts between males and females by species.

data4 <- penguins

ggplot(data4, aes(x = sex, fill = species)) +
  geom_bar() +
  facet_wrap( ~ species, ncol = 1) +
  coord_flip() +
  labs(x = "Gender",
       y = "Count")

  1. Scatterplot

This figure examines the relationship between bill length and depth in the penguins dataset.

data5 <- penguins

ggplot(data = data5, aes(x = bill_length_mm, y = bill_depth_mm,color = species)) +
  geom_point(aes(color = species), size = 1)  +
  geom_smooth(method = "lm", se = FALSE) +
  labs(
    x = 'Bill Length',
    y = 'Bill Depth')