Directions

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.

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.

Questions

Find the mtcars data in R. This is the dataset that you will use to create your graphics.

  1. Create a pie chart showing the proportion of cars from the mtcars data set that have different carb values and write a brief summary.
pie(table(mtcars$carb),main='Cars on differnt carb value')

Based on above, I can see car with 4 Carb occupies in the dataset, and then 2 carb and 1 carb follow up.

  1. Create a bar graph, that shows the number of each gear type in mtcarsand write a brief summary.
barplot(table(mtcars$gear),main = 'Gear Values', xlab = '# of gear')

From above barplot, I can see 3 gear has more than 14 counts, and 4 gear is in the secondary place.

  1. Next show a stacked bar graph of the number of each gear type and how they are further divided out by cyland write a brief summary.
gear <- table(mtcars$cyl,mtcars$gear)
barplot(gear,main='values of gear by cyl',xlab='# of gear', col=c("orange","blue","purple"),legend = rownames(gear))

According to the graph, I can see cars with 8 cyl are the primary type in 3 gear cars, 4 cyl occupies 4 gear cars.

  1. Draw a scatter plot showing the relationship between wt and mpgand write a brief summary.
plot(mtcars$wt,mtcars$mpg,main="Relationship between wt and mpg", xlab="wt",ylab="mpg", pch=20)

Per above scatter plot, I can see a negative relationship between wt and mpg. When car weight is low, mile per gallon is high.

  1. Design a visualization of your choice using the data and write a brief summary about why you chose that visualization.
plot(mtcars$hp,mtcars$cyl,main="Relationship between hp and cyl", xlab="hp",ylab="cyl", pch=20)

I displayed relationship between hourse power and cyl based on the mtcars database, since I want to verify the theory that the car with more powerful hp would be equipped with more cyl. Based on the findings, I can confidently claim that the relationship between hp and cyl is positive and the theory can be validated.