Questions

library(ggplot2)
ggplot(mpg,aes(x = factor(mpg$class),fill=factor(mpg$trans))) +
scale_fill_discrete("Transmission") +
xlab("Class") +
ylab("Count") +
geom_bar()

ggplot(mpg, aes(y=mpg$hwy, x=mpg$manufacturer)) + 
geom_boxplot() +
coord_flip() +
ylab("Highway Fule Efficiency(miles/gallon)") +
xlab("Vehicle manufacturer") 

  1. Next show a stacked bar graph of the number of each gear type and how they are further divded out by cyl.
library(ggthemes)
ggplot(diamonds) +
  geom_density(aes(diamonds$price, fill= cut, color= cut), alpha=0.4)+
  theme_economist()+
  labs(x = "Diamond Price (USD)",
  y = "Density",
  title = "Diamond Price Density")

4. Draw a scatter plot showing the relationship between wt and mpg.

p <-ggplot(iris, aes(x = Petal.Width, y = Sepal.Length)) + 
geom_point() +
stat_smooth(method = "lm", col = "blue")+
ylab("Iris Petal Length") +
xlab("Iris Sepal Length") 
p + labs(title = "Relationship between Petal and Sepal Length")

  1. Design a visualization of your choice using the data.
iris_graph <- ggplot(iris, aes(x=Sepal.Length, y=Petal.Length, colour = factor(Species))) +
  geom_point() +
  ggtitle("Relationship between Petal and Sepal Length")
iris_graph + geom_smooth(method = "lm", se = FALSE) +
  scale_color_fivethirtyeight("Species") +
  theme_fivethirtyeight()