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.
# place the code to import graphics here
data(mtcars)
View(mtcars)
carb<-table(mtcars$carb)
pie(carb)

# Summary:
# This pie chart could show the number of cars that with same carb number and how their proportion is. The carb number of "2" has the largest amount of cars and the carb number "4" has the second large amount of cars. And the carb number 6/8 has the least cars nunmber.
  1. Create a bar graph, that shows the number of each gear type in mtcarsand write a brief summary.
# place the code to import graphics here
Number<-table(mtcars$gear)
barplot(Number,main="Total",xlab="Gear amount")

# Summary: from the following barplot, we could tell that there are only three number of gear amount in this data set and the gear amount "3" has the largest amount of cars. As for the gear amount "5", it has the least car number. So the "3" and "4" gear type cars are easier to find. 
  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.
# place the code to import graphics here
Number2<-table(mtcars$cyl,mtcars$gear)
barplot(Number2,main="Total by cyle and gear",xlab = "Gear amount")

# Summary: This barplot has two factors in the horizontal direction. The gear amount and the cycle amount could both be observed in this chart. We could tell in the "3" category the cycle number has different distribution in it. 
  1. Draw a scatter plot showing the relationship between wt and mpgand write a brief summary.
# place the code to import graphics here
data("mtcars")
attach(mtcars)
## The following object is masked _by_ .GlobalEnv:
## 
##     carb
plot(wt,mpg,main="Mtcars plot", xlab = "car weight",ylab = "miles one gallon")

#Summary: From this plot chart, we could see the data is kind of central distribution. cars with media weight and media miles one gallon has the largest quantity. There are only three cars with the car weight over"5"and many cars have the weight between "3" and "4" and have the miles one gallon around "15" 
  1. Design a visualization of your choice using the data and write a brief summary about why you chose that visualization.
# place the code to import graphics here
boxplot(mpg~hp,data=mtcars,main="mpg data",xlab="number of hp",ylab="number of mpg")

#Summary: The reason I use the box plot to do the visualizaion is that the box plot could see the media of the group date and we could have a better view of the data and the range of some data could also give us a clear picture that how the data is distributed.