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.
pie(table(mtcars$carb),main="Carb by Car")

# place the code to import graphics here

Above pie chart shows that most of cars carb is 2 or 4. and only small portion of cars have high carbs.

  1. Create a bar graph, that shows the number of each gear type in mtcars.
barplot(table(mtcars$gear),main="Gear",xlab='Number of Gears')

# place the code to import graphics here

Most of cars have 3 or 4 gears, and few cars have 5 gears.

  1. Next show a stacked bar graph of the number of each gear type and how they are further divided out by cyl.
Count <- table(mtcars$cyl, mtcars$gear)
barplot(Count,main='Car by Gears and Cyl',xlab='Number of Gears', col=c("red","green",'blue'),legend = rownames(Count))

# place the code to import graphics here

For 3 gear cars, most of that has 8 cyl, and few has 4 cyl. In contrast, most of 4 gear cars have 4 cyl, and none of that have 8 gears. 5 gear cars have 8 cyl, 6 cyl and 4 cyl options.

  1. Draw a scatter plot showing the relationship between wt and mpg.
plot(mtcars$wt, mtcars$mpg, main="Scatterplot", 
 xlab="Weight ", ylab="Miles Per Gallon ")

# place the code to import graphics here

The relationship between weight and mpg is close. Above scatterplot indicates that heavier cars have lower mpg, and high mpg car usually has lower weight.

  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$mpg, main="Scatterplot", 
xlab="horse power ", ylab="mpg ")

# place the code to import graphics here

I want to study how horse power will impact the mpg to find the best car that utilize the gas. From the scatterplot we could see that higher horse power leads to lower mpg, and vice versa.