1.Create a pie chart showing the proportion of cars from the mtcars data set that have different carb values.
carb <- mtcars$carb
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.freq <- table(carb)
carb.freq
## carb
## 1 2 3 4 6 8
## 7 10 3 10 1 1
pie(carb.freq)

slices <- c(carb.freq)
slices
## 1 2 3 4 6 8
## 7 10 3 10 1 1
labels <- c("carb of 1 is", "carb of 2 is", "carb of 3 is", "carb of 4 is", "carb of 6 is", "carb of 8 is")
labels
## [1] "carb of 1 is" "carb of 2 is" "carb of 3 is" "carb of 4 is"
## [5] "carb of 6 is" "carb of 8 is"
percentage <- round(slices/sum(slices)*100,2)
percentage
## 1 2 3 4 6 8
## 21.88 31.25 9.38 31.25 3.12 3.12
labels <- paste(labels, percentage, "%")
labels
## [1] "carb of 1 is 21.88 %" "carb of 2 is 31.25 %" "carb of 3 is 9.38 %"
## [4] "carb of 4 is 31.25 %" "carb of 6 is 3.12 %" "carb of 8 is 3.12 %"
pie(slices,labels = labels, col=rainbow(length(labels)), main="Pie Chart of carbs")

The result shows that cars with carb(carburetors) of 2 and 4 have the most value (31.25%) while cars with carbs 6 and 8 have the least percentage of vales (3.12%)
2.Create a bar graph, that shows the number of each gear type in mtcars.
gear <- mtcars$gear
gear
## [1] 4 4 4 3 3 3 3 4 4 4 4 3 3 3 3 3 3 4 4 4 3 3 3 3 3 4 5 5 5 5 5 4
gear.freq <- table(gear)
gear.freq
## gear
## 3 4 5
## 15 12 5
barplot(gear.freq, main="Gear Distribution",xlab="Number of Gears",ylab="Number of cars",col=rainbow(length(gear.freq)))

This graph shows that cars with 3 Gears have the highest distribution among all of them and is more than 12 which is 15 in its frequency table and cars with 4 gears is in next level of frequency ans cars with 5 gears are in last level and are less than 6.
3.Next show a stacked bar graph of the number of each gear type and how they are further divided out by cyl.
a <- table(mtcars$cyl, mtcars$gear)
a
##
## 3 4 5
## 4 1 8 2
## 6 2 4 1
## 8 12 0 2
barplot(a, main="Distribution of Gears devided by cyl",names.arg=c("3 Gears", "4 Gears", "5 Gears"),
cex.names =0.8, xlab="Number of gear", ylab="Number of Cars", col=c("green","red","blue"),legend = rownames(a))

This stacked bar shows that the majority of 3 gears cars have 8 cylinders while none of the 4 gear cars are 8 cylinders.It seems cars with 4 gears and 4 cylinders are 2 times more than cars with 4 gears and 6 cylinders. The propotion of 6 cylinder cars is the smalles for 5 gears cars.
4.Draw a scatter plot showing the relationship between wt and mpg.
plot(mtcars$wt,mtcars$mpg,main = "scatter plot of weight vs mpg",xlab = "car weight",ylab= "mile per gallon")

The graph shows that by increasing the wt (weight of the car) its mpg(Milage per gallon) is decreased.
5. Design a visualization of your choice using the data and write a brief summary about why you chose that visualization.
wt <- mtcars$wt
wt
## [1] 2.620 2.875 2.320 3.215 3.440 3.460 3.570 3.190 3.150 3.440 3.440
## [12] 4.070 3.730 3.780 5.250 5.424 5.345 2.200 1.615 1.835 2.465 3.520
## [23] 3.435 3.840 3.845 1.935 2.140 1.513 3.170 2.770 3.570 2.780
hp <-mtcars$hp
hp
## [1] 110 110 93 110 175 105 245 62 95 123 123 180 180 180 205 215 230
## [18] 66 52 65 97 150 150 245 175 66 91 113 264 175 335 109
a <- lm(formula = hp~wt,data=mtcars)
plot(hp~wt, ylab="Gross horsepower" , xlab="Car Weight")
abline(a , col="green")

This plot shows with increasing the car weight, the horsepower of car will increase as well and vise versa.