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 Canvas. 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 box plot using ggplot showing the range of values of 1/4 mile time (qsec) for each tansmission type (am, 0 = automatic, 1 = manual) from the mtcars data set.
# place the code to import graphics here
library(ggplot2)
mtcars$am[mtcars$am == 0]='automatic'
mtcars$am[mtcars$am == 1]='manual'
mtcars$am =as.factor(mtcars$am)
ggplot(mtcars,aes(x=am,y=qsec)) + geom_boxplot()+xlab("am")+ylab("qsec")

Note:Automatic’s all level quartile is bigger than manual which means automatic needs more time in terms of am.

  1. Create a bar graph using ggplot, that shows the number of each carb type in mtcars.
# place the code to import graphics here
ggplot(mtcars,aes(x= carb))+ geom_bar(stat = "Count")

Note: The column 2 and 4 have more counts than the others. 3. Next show a stacked bar graph using ggplot of the number of each gear type and how they are further divided out by cyl.

# place the code to import graphics here
ggplot(mtcars,aes(x =factor(cyl), fill=factor(gear)))+xlab("cyl")+ ylab("gear")

Note: No.4 gear is the highest among having 4,6 cylinders. No.3 is the highest among having 8 cylinders.
4. Draw a scatter plot using ggplot showing the relationship between wt and mpg.

ggplot(mtcars,aes(wt,mpg))+ xlab("wt")+ylab("mpg")

Note: Wt and mpg has a negative correlation which means the lower the weight goes, the higher the mpg is. 5. Design a visualization of your choice using ggplot using the data and write a brief summary about why you chose that visualization.

ggplot(mtcars, aes(x = cyl, fill = am)) + geom_bar() + facet_grid(.~gear)

Note:Type 3 gears are having the most cylinders. while type 5 Gear are manual and have less cyclinders. This means typically automatic has more cyclinders than in manual. This allows us to know that how manual and automatic work in a different way in terms of cyclinders.