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 is preprocessing involved in many 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 of your graphics.
The final product of your homework (this file) should include a short summary of each graphic.
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 Moodle. Please make sure that this link is hyperlinked and that I can see the visualization and the code required to create it.
Find the mtcars data in R. This is the dataset that you will use to create your graphics.
mtcars data set that have different carb values.# place the code to import graphics here
prop <- table(mtcars$carb)
lab <- paste(round(prop/nrow(mtcars)*100), "%")
pie(prop, labels=lab, main = "Proportion of Carburetors", col=rainbow(6))
legend("topleft", legend=names(prop), fill=rainbow(6), title="Carburetors")
gear type in mtcars.# place the code to import graphics here
ger <- table(mtcars$gear)
barplot(ger
, main="Number of cars for different gears"
, xlab="Number of Gears"
, ylab="Number of Cars"
, ylim=c(0,18))
gear type and how they are further divided out by cyl.# place the code to import graphics here
gearcyl <- table(mtcars$cyl, mtcars$gear)
barplot(as.matrix(gearcyl)
, main="Number of cars for different gears grouped by number of cylinders"
, xlab="Number of Gears"
, ylab="Number of Cars"
, ylim=c(0,18)
, legend.text=TRUE
, args.legend=list(x="topright", title="Cylinders"))
wt and mpg.# place the code to import graphics here
plot(mtcars$wt ~ mtcars$mpg
, xlab="Miles per Gallon"
, ylab="Weight (1000 lbs)"
, main="Scatter plot of mpg vs wt for mtcars"
, pch=20)
# place the code to import graphics here
mpg1 <- subset(mtcars, cyl==4)
mpg2 <- subset(mtcars, cyl==6)
mpg3 <- subset(mtcars, cyl==8)
par(mfrow=c(3,1))
xlim = c(0,40)
hist(mpg1$mpg, main = "Histogram of mpg for cyl = 4", xlab="Miles per Gallon", xlim=xlim)
hist(mpg2$mpg, main = "Histogram of mpg for cyl = 6", xlab="Miles per Gallon", xlim=xlim)
hist(mpg3$mpg, main = "Histogram of mpg for cyl = 8", xlab="Miles per Gallon", xlim=xlim)