Directions

During ANLY 512 we will be studying the theory and practice of data visualization. We will be using R and the packages within R to assemble data and construct many different types of visualizations. We begin by studying some of the theoretical aspects of visualization. To do that we must appreciate the basic steps in the process of making a visualization.

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

The final product of your homework (this file) should include a short summary of each graphic.

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 hyperlinked and that I can see the visualization and the code required to create it.

———————my work area————————

#ggplot(mpg, aes(x = displ, y = hwy)) + geom_point() #install.packages(“tidyverse”) #install.packages(“ggplot2”) #install.packages(“mpg”) #head(mpg) ## Questions

#library(tidyverse) #ggplot2::ggplot() #ggplot2::mpg #head(mpg) # ———————————————

Find the mpg data in R. This is the dataset that you will use for the first three questions.

  1. Create a box plot using ggplot showing engine displacement displ for each transmission type trans from the mpg data set. Hint: Can you figure out how to rotate the x-axis categories so they are all readable?
p <- ggplot(mpg,aes(x=displ,y=trans)) + geom_boxplot()
p + labs(x ="Displacement",y="Transmission Type",title = "Question 1",caption = "This visualization is showing Engine displacement of each Transmission type.")

  1. Create a histogram or bar graph using ggplot, that shows the frequency of each class type in mpg.
# place the code to import graphics here

p <- ggplot(mpg,aes(x=class)) + geom_bar()
p + labs(x="Class", y="Mile per gallon",title = "Question 2",caption = "This visualization is showing each class of vehicles with their mile per gallon.")

#==============================>>>> #==============================>>>> #==============================>>>>

  1. Next show a stacked bar graph using ggplot, that shows the frequency of each cyl type within class. Hint:You might have to use (group) or convert cyl to a factor (as.factor). ggplot(mpg, aes(x = displ, y = hwy)) + geom_point() #==============================>>>> #==============================>>>> #==============================>>>>
# place the code to import graphics here
#p<- ggplot(mpg, aes(x=cyl)) + geom_bar(position="stack")
#p + labs(x="Class",title = "Question 3")

p <- ggplot(mpg, aes(x = class, y = cyl))+
  geom_col(aes(fill = cyl), width = 0.9)+
  labs(x = "Class",y = "Clynder",title = "Question 3",caption = "This visualization is showing each clyinder by classes grouped.")
p

  1. Draw a scatter plot using ggplot showing the relationship between cty and hwy. Explain the utility or lack of utility of this graphic.
# place the code to import graphics here
p <- ggplot (mpg , aes(x = cty,y=hwy)) + geom_point()
p + labs (x="City",y="Highway",title = "Question 4",caption = "This visualization is showing the relationship between miles per gallan between city and highway miles.")

  1. Design a visualization of your choice using ggplot using mpg and write a brief summary about why you chose that visualization.
# place the code to import graphics here
p <- ggplot(mpg, aes(x=class, y=cty, shape = class ,color=cyl)) +  geom_point()
p + labs(x="Class",y="City",tittle = "Question 5",caption = "I chose this visualization to see the how the class of vehicle are better in city")

#head(mpg)