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
ggplot(mpg, aes(x=trans, y=displ)) +
geom_boxplot()+
theme(axis.text.x = element_text(angle = 90)) +
ylab(label = "Engine Displacement") +
xlab(label = "Transmission type") +
labs(title = "Engine displacement for each transmission type")
class type in mpg.# place the code to import graphics here
ggplot(mpg, aes(x = class)) + geom_bar()+
labs(title = "Frequency of classes") +
xlab(label = "Class")
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(mpg, aes(x = class, fill = factor(cyl))) +
geom_bar(width = 1) +
labs(title = "Frequency of each cyl within a class")
cty and hwy. Explain the utility or lack of utility of this graphic.# place the code to import graphics here
ggplot(mpg, aes(cty, hwy)) +
geom_point()+geom_smooth()+
ylab(label = "Highway MPG") +
xlab(label = "City MPG") +
labs(title = "City vs. Highway MPG")
The above graph shows a direct proportionality between "City MPG" and "Highway MPG". Let's say there are two cars - Car A and Car B. If Car A's "City MPG" is greater than that of Car B, then Car A's "Highway MPG" is bound to be greater than that of Car B.
mpg and write a brief summary about why you chose that visualization.# place the code to import graphics here
ggplot(mpg, aes(displ, cty)) +
geom_point()+geom_smooth()+
ylab(label = "City MPG") +
xlab(label = "Engine Displacement") +
labs(title = "Engine Displacement vs. City MPG")
The above graph shows an indirect proportionality between "Engine Displacement" and "City MPG". More the "Engine Displacement", less is the "City MPG". Hence, it's a challenge to get great mileage on high-end automobiles.