getwd() setwd(“C:/Users/Jason/Desktop/Harrisburg University/Analytics_512-51-2017”) library(datasets) head(mtcars)

Questions

Find the mtcars data in R. This is the dataset that you will use to create your graphics. Use that data to draw by hand graphics for the next 4 questions.

  1. Draw a pie chart showing the proportion of cars from the mtcars data set that have different carb values.
# place the code to import graphics here
mtcars$carb
##  [1] 4 4 1 1 2 1 4 2 2 4 4 3 3 3 4 4 4 1 2 1 1 2 2 4 2 1 2 2 4 6 8 2
carb <- table(mtcars$carb)
carb
## 
##  1  2  3  4  6  8 
##  7 10  3 10  1  1
pie(carb,main = "Proportion of cars from the `mtcars` data set by Carb type", labels = names(carb))

library(knitr)
knitr::include_graphics('1.JPG', dpi = NA)

  1. Draw a bar graph, that shows the number of each gear type in mtcars.
# place the code to import graphics here
mtcars$gear <- as.factor(mtcars$gear)
barplot(summary(mtcars$gear), xlab = "Gear Type", ylab = "Number of Gear",
        main = "Bar Graph of Gear Variable in mtcars",ylim = c(0,20))

library(knitr)
knitr::include_graphics('2.JPG', dpi = NA)

  1. Next show a stacked bar graph of the number of each gear type and how they are further divded out by cyl.
# place the code to import graphics here
covtable <- table(mtcars$cyl,mtcars$gear)
covtable
##    
##      3  4  5
##   4  1  8  2
##   6  2  4  1
##   8 12  0  2
barplot(covtable,xlab = "Gear Type", ylab = "Number of Gear",
        main = "Bar Graph of Gear Variable with Cyl distribution",ylim = c(0,20),
        col=c("red","yellow","green"),legend=(rownames(covtable)))

library(knitr)
knitr::include_graphics('3.JPG', dpi = NA)

  1. Draw a scatter plot showing the relationship between wt and mpg.
# place the code to import graphics here
plot(mtcars$wt,mtcars$mpg,xlab = "wt", ylab = "mpg",main = "scatter plot of wt vs mpg" )

library(knitr)
knitr::include_graphics('4.JPG', dpi = NA)

  1. Design a visualization of your choice using the data.
# place the code to import graphics here
plot(mtcars$wt, type = "l", ylab = "Weight", xlab = "Row Number", main = " Line Example")

library(knitr)
knitr::include_graphics('5.JPG', dpi = NA)