1. Create a pie chart showing the proportion of cars from the 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%.

  1. Create a bar graph, that shows the number of each gear type in mtcarsand 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.

  1. Next show a stacked bar graph of the number of each gear type and how they are further divided out by cyland 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.

  1. Draw a scatter plot showing the relationship between wt and mpgand 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.

  1. Design a visualization of your choice using the data and write a brief
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.