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 and write a brief summary.# place the code to import graphics here
question1 <- as.data.frame(table(mtcars$carb))
with(question1,pie(Freq,labels=paste0("carb ",Var1,", ",round(Freq/sum(Freq)*100,2),"%"),main="Pie Chart of 'carb'",col=rainbow(length(Var1))))
# SUMMARY
# The 'carb' values in decreasing order are carb 2, 4, 1, 3, 6, and 8 with percentage 31.25%, 31.25%, 21.88%, 9.38%, 3.12%, and 3.12% respectively.
# carb 2 and 4 have the same proportion, while carb 6 and 8 have the same proportion.
gear type in mtcarsand write a brief summary.# place the code to import graphics here
question2 <- table(mtcars$gear)
p2 <- barplot(question2,main="Bar Plot of 'gear'",xlab="Number of Gears",ylab="Counts",ylim=c(0,max(question2)+5),border=F)
text(x=p2,y=question2,label=question2,pos=3,col="red")
# SUMMARY
# The 'gear' types in decreasing order are gear 3, 4, and 5 with value 15, 12, and 5 respectively.
gear type and how they are further divided out by cyland write a brief summary.# place the code to import graphics here
question3 <- table(mtcars$cyl,mtcars$gear)
barplot(question3,main="Stacked Bar Plot of 'gear' and 'cyl'",xlab="Number of Gears",ylab="Counts",ylim=c(0,max(colSums(question3))+5),col=c("black","grey","white"),legend=paste0(rownames(question3),"-cyl"))
# SUMMARY
# As for 3-gear type, 8-cyl accounts for the most.
# As for 4-gear type, 4-cyl accounts for the most, and there is no 8-cyl.
# As for 5-gear type, 4-cyl, 6-cyl, and 8-cyl are roughly the same.
wt and mpgand write a brief summary.# place the code to import graphics here
plot(mtcars$wt,mtcars$mpg,xlab="Weight (lb/1000)",ylab="Miles/US Gallon (mpg)",main="Scatter Plot of 'wt' and 'mpg'",ylim=c(min(mtcars$mpg)-5,max(mtcars$mpg)+5),xlim=c(min(mtcars$wt)-0.5,max(mtcars$wt)+0.5))
# SUMMARY
# There is a downward trend from the relationship bewteen 'wt' and 'mpg': in general as 'wt' increases, mpg will decrease.
# place the code to import graphics here
# I will take a quick look at the built-in dataset called 'airquality', which records some weather conditions from May 1 to September 30 in 1973 in New York.
# Since the dataset can be formulated as a time series, the line chart as a visualization is chosen to examine the trend.
question5 <- ts(airquality$Ozone)
plot(question5,ylab="Ozone (ppb)",main="Time Series of 'Ozone'",sub="May 1 - September 30, 1973, New York")
# SUMMARY
# There are lots of missing values (NA) in the dataset.
# The data fluctuated during the three-quarters of the period.