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 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 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 mtcars data in R. This is the dataset that you will use to create your graphics.
data(mtcars)
summary(mtcars)
## mpg cyl disp hp
## Min. :10.40 Min. :4.000 Min. : 71.1 Min. : 52.0
## 1st Qu.:15.43 1st Qu.:4.000 1st Qu.:120.8 1st Qu.: 96.5
## Median :19.20 Median :6.000 Median :196.3 Median :123.0
## Mean :20.09 Mean :6.188 Mean :230.7 Mean :146.7
## 3rd Qu.:22.80 3rd Qu.:8.000 3rd Qu.:326.0 3rd Qu.:180.0
## Max. :33.90 Max. :8.000 Max. :472.0 Max. :335.0
## drat wt qsec vs
## Min. :2.760 Min. :1.513 Min. :14.50 Min. :0.0000
## 1st Qu.:3.080 1st Qu.:2.581 1st Qu.:16.89 1st Qu.:0.0000
## Median :3.695 Median :3.325 Median :17.71 Median :0.0000
## Mean :3.597 Mean :3.217 Mean :17.85 Mean :0.4375
## 3rd Qu.:3.920 3rd Qu.:3.610 3rd Qu.:18.90 3rd Qu.:1.0000
## Max. :4.930 Max. :5.424 Max. :22.90 Max. :1.0000
## am gear carb
## Min. :0.0000 Min. :3.000 Min. :1.000
## 1st Qu.:0.0000 1st Qu.:3.000 1st Qu.:2.000
## Median :0.0000 Median :4.000 Median :2.000
## Mean :0.4062 Mean :3.688 Mean :2.812
## 3rd Qu.:1.0000 3rd Qu.:4.000 3rd Qu.:4.000
## Max. :1.0000 Max. :5.000 Max. :8.000
cyl=table(mtcars$cyl)
data.labels=names(cyl)
percent=round(cyl/sum(cyl)*100)
data.labels=paste("cylinder",data.labels,":")
data.labels=paste(data.labels,percent)
data.labels=paste(data.labels,"%", sep="")
pie(cyl, labels = data.labels, clockwise = TRUE, col = heat.colors(length(data.labels)), main="Frequency of car cylinder")
#Data Summury:the chart shows the proportion of cars have different cylinder. 4 cylinder cars are 34% of total. And 6 cylinder cars are 22%, cylinder 8 cars are 44%
carb=table(mtcars$carb)
barplot(carb,main ="Number of cars in type", xlab = "Type of car", ylab = "Number of cars", names.arg = names(carb), col = rainbow(6))
# Data Summary: The number of cars in each type are show as bars. from it, the car 2 and 4 are the highest in the distribution, and car 6 and 8 are the lowest.
cyl.gear=table(mtcars$cyl,mtcars$gear)
barplot(cyl.gear, main = "Distribution of gears by cylinder", xlab = "Number of gears", ylab="number of cylinder",names.arg = names(cyl.gear), cex.names = 0.8, col=rainbow(3),legend=rownames(cyl.gear))
# Data Summary: The plot shows the 3 gears uses 8 cylinders most, and 4 gears only use 4 and 6 cylinder, and 5 gears uses 4 and 8 cylinder most.
plot(mtcars$wt, mtcars$mpg, main = "relation between Mileage and weight", xlab = "weight", ylab = "MPG", col="black")
# Data summary: the plot shows that the weight increase will readuce the MPG,which means heavy car has bad gas use performance
plot(mtcars$hp, mtcars$mpg, main = "relation between Mileage and hoursepower", xlab = "HP", ylab = "MPG", col="black")
lines(lowess(mtcars$hp, mtcars$mpg),col="red")
# data summary: the plot indicate the relation between horsepower and mileage, the stronger horsepower car has less MPG performance.