mtcars
data set that have different carb
values and write a brief summary.carb=table(mtcars$carb)
lbls=names(carb)
pct=round(carb/sum(carb)*100)
lbls=paste(lbls,pct)
lbls=paste(lbls,"%",sep = "")
pie(carb,labels = lbls,main = "Pie Chart of Carb")
From the pie chart, we can see that the cars with 1,2 and 4 carbs have larger proportions than cars with 3,6,8 carbs. Cars with 4 carbs have the largest proportion of 31% and cars with 6 and 8 carbs have a proportion of only 3%.
gear
type in mtcars
and write a brief summary.gear=table(mtcars$gear)
barplot(gear,main = "Number of Car Gear",xlab = "Number of Gears")
In the barplot, the 3-gear cars have the largest number of more than 14. The 4-gear cars are about 12, and the 5-gear cars are around 5.
gear
type and how they are further divided out by cyl
and write a brief summary.gear=table(mtcars$cyl,mtcars$gear)
barplot(gear,main = "Cars with Different Gears and cyl",xlab = "Number of Gears",ylab="Number of Cars",col = c("red","blue","yellow"),legend=rownames(gear))
Among the cars that have 3 gears, most of them have 8 cylinders. For those cars that have 4 gears, most of them have 4 cylinders and none of them have 8 cylinders. In the cars that have 5 gears, the number of cars with 4 and 8 gears are almost the same.
wt
and mpg
and write a brief summary.plot(mtcars$wt,mtcars$mpg,main = "Weight and Miles per Gallon",xlab = "weight",ylab = "miles per gallon",pch=19)
abline(lm(mtcars$mpg~mtcars$wt),col="pink")
The pink line in the graph shows that there is a negative relationship between weight and mpg.
a=density(mtcars$mpg)
plot(a,col="purple",main = "Density of MPG")
It shows that most of the cars have a mpg near 20 miles. Cars with a 30 miles per gallon have a density of about 0.02.