The objectives of this problem set is to gain experience working with the ggplot2 package for data visualization. To do this I have provided a series of graphics, all created using the ggplot2 package. Your objective for this assignment will be write the code necessary to exactly recreate the provided graphics.
library(ggplot2)
Vis1<-ggplot(data=mpg,aes(x=class,fill=trans))+geom_bar()+scale_fill_discrete(name="Transmission")
Vis1
This boxplot is also built using the mpg dataset. Notice the changes in axis labels, and an altered theme_XXXX
Visual2<-ggplot(data=mpg,aes(y=hwy,x=manufacturer))+coord_flip()+geom_boxplot()+theme_classic()+labs(x="Vehicle Manufacturer", y="Highway Fuel Efficiency(miles/gal)")
Visual2
Create scatter plots for each x,y pair of data.
library(ggthemes)
## Warning: package 'ggthemes' was built under R version 3.4.4
Visual3<-ggplot(diamonds, aes(x=price,fill=cut,color=cut))+geom_density(alpha=0.2)+labs(x="Diamond Price(USD)", y="Density", title="Diamond Price Density")+theme_economist()
Visual3
Now change the symbols on the scatter plots to solid circles and plot them together as a 4 panel graphic
Visual4<-ggplot(iris,aes(x=Sepal.Length, y=Petal.Length))+geom_point()+geom_smooth(method = lm)+labs(title="Petal and Sepal Length relationship", x="Iris Sepal Length", y="Iris Petal Length")+theme_minimal()
Visual4
Now fit a linear model to each data set using the lm() function.
Visual5<-ggplot(iris,aes(x=Sepal.Length, y=Petal.Length,color=Species))+geom_point()+geom_smooth(method = lm,se=F)+labs(title="Petal and Sepal Length relationship",subtitle = "Species level comparison",x="Iris Sepal Length", y="Iris Petal Length")+theme_tufte()+theme(legend.position = "bottom")
Visual5