R Markdown

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.
carb <- table(mtcars$carb)
pie(carb,main="Proportion of cars with different carb values")

  1. Create a bar graph, that shows the number of each gear type in mtcars.
gear <- table(mtcars$gear)
barplot(gear,xlab="Gear Type", ylab= "Count", main="Number of Each Gear Type", col=gear)

  1. Next show a stacked bar graph of the number of each gear type and how they are further divided out by cyl.
gear_cyl <- table(mtcars$cyl,mtcars$gear)
barplot(gear_cyl, xlab="Gear Type", ylab="Counts of Gear",main="Number of Each Gear Type Divided Out by cyl",col=c("yellow","green","blue"),legend=(rownames(gear_cyl)))

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

  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,xlab="Horse Power", ylab="Miles Per Gallon", main="Relationship Between hp & mpg",pch=16)
abline(lm(mtcars$mpg~mtcars$hp),col="blue")

From the plot, we can see there is a negative correlation between horse power and miles per gallon of cars.