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.
A couple of tips, remember that there may be preprocessing involved in your graphics so you may have to do summaries or calculations to prepare, those should be included in your work.
To ensure accuracy pay close attention to axes and labels, you will be evaluated based on the accuracy and expository nature of your graphics. Make sure your axis labels are easy to understand and are comprised of full words with units if necessary.
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.
Find the mpg data in R. This is the dataset that you will use for the first three questions.
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?# place the code to import graphics here
library(ggplot2)
data(mpg)
boxplot(displ~trans,data=mpg, ylab="Engine Displacement",xlab="", las=2)
mtext("Transmission Type", side=3)
class type in mpg.# place the code to import graphics here
library(ggplot2)
ggplot(data.frame(mpg), aes(x=class))+geom_bar()
cyl type within class. Hint:You might have to use (group) or convert cyl to a factor (as.factor).# place the code to import graphics here
ggplot(data.frame(mpg), aes(x=class,fill = cyl,las=2)) + geom_bar()+theme(axis.text.x=element_text(angle=90,hjust=1))
cty and hwy. Explain the utility or lack of utility of this graphic.# place the code to import graphics here
ggplot(mpg, aes(x = cty, y = hwy))+geom_point()
#This plot basically shows that highway miles per gallon is mostly linearly proportional to city miles per gallon. It is not a useful graph since miles per gallon should be same irrespective of highway or city.
mpg and write a brief summary about why you chose that visualization.# place the code to import graphics here
ggplot(mpg, aes(x=displ, y=hwy+cty, color=drv, shape=drv)) +geom_point()+geom_smooth(method=lm)
#This plot tries to identify the relation between engine displacement and miles per gallon for different types of drive train.Miles per gallon decreases as engine displacement increases as a general trend for all drive types though there are outliers in the trend lines.