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.
When completed submit a link to your file on rpubs.com. Be sure to include echo = TRUE for each graphic so that I can see the visualization and the code required to create it.
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.3.3
library(ggthemes)
## Warning: package 'ggthemes' was built under R version 3.3.3
ggplot(data = mpg, aes(x = class, fill = trans)) +
geom_bar() +
scale_fill_discrete(name = 'Transmission')
ggplot(data = mpg, aes(x = manufacturer, y = hwy)) +
geom_boxplot() +
coord_flip() +
xlab('Vehicle Manufacturer') +
ylab('Highway Fuel Efficiency (miles/gallon)') +
theme_classic()
ggplot(data = diamonds, aes(x = price, fill = cut, color = cut)) +
geom_density(alpha = 0.3) +
ggtitle('Diamond Price Density') +
xlab('Diamond Price (USD)') +
ylab('Density') +
theme_economist()
ggplot(data = iris, aes(x = Sepal.Length, y = Petal.Length)) +
geom_point() +
geom_smooth(method = 'lm') +
ggtitle('Relationship between Petal and Sepal Length') +
xlab('iris Sepal Length') +
ylab('iris Petal Length')
ggplot(data = iris, aes(x = Sepal.Length, y = Petal.Length, col = Species)) +
geom_point() +
geom_smooth(method = 'lm', se = FALSE) +
ggtitle('Relationship between Petal and Sepal Length', subtitle = 'Species level comparison') +
xlab('iris Sepal Length') +
ylab('iris Petal Length') +
theme_tufte()