Questions
Find the mtcars data in R. This is the dataset that you will use to create your graphics.
carb <- table(mtcars$carb)
pie(carb,main="Proportion of cars with different carb values")
gear <- table(mtcars$gear)
barplot(gear,xlab="Gear Type", ylab= "Count", main="Number of Each Gear Type", col=gear)
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)))
plot(mtcars$wt,mtcars$mpg,xlab="wt",ylab="mpg",main="Relationship between wt and mpg")
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.