Questions
- Draw a pie chart showing the proportion of cars from the
mtcars data set that have different carb values.
library(ggplot2)
ggplot(data=mtcars,
aes(x = factor(1), fill = factor(carb))) +
ylab("Proportions of cars by carb value") + xlab("") +
geom_bar(width = 1) +
coord_polar(theta = "y")

knitr::include_graphics("IMG_3074.JPG")

- Draw a bar graph, that shows the number of each
gear type in mtcars.
ggplot(data=mtcars,aes(x=gear)) + geom_bar(stat="Count",colour="#FF9999") + ggtitle("Number of each Gear type in mtcars")

knitr::include_graphics("IMG_3075.JPG")

- Next show a stacked bar graph of the number of each
gear type and how they are further divded out by cyl.
ggplot(mtcars,
aes(x = factor(gear), fill = factor(cyl))) +
xlab("Gears") +
ylab("Cylinders") + geom_bar()

knitr::include_graphics("IMG_3076.JPG")

- Draw a scatter plot showing the relationship between
wt and mpg.
ggplot(mtcars, aes(x = wt, y = mpg)) +
xlab("Car Weight") + ylab("mpg") +
geom_point() +
geom_line() +
ggtitle(" Car Weight vs Miles Per Gallon") +
stat_smooth(method ='lm')

knitr::include_graphics("IMG_3077.JPG")

- Design a visualization of your choice using the data.
plot(mtcars$disp, mtcars$mpg, xlab="Engine displacement", ylab="mpg", main="MPG vs engine displacement", las=1)

knitr::include_graphics("IMG_3078.JPG")
