# Install and library the ggplot2 and ggthemes
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.4.1
library(ggthemes)
## Warning: package 'ggthemes' was built under R version 3.4.1
You can also embed plots, for example:
ggplot(data = mpg, aes(x = class, fill = trans)) +
geom_bar() +
scale_fill_discrete(name = 'Transmission')
## Vis 2
ggplot(data = mpg, aes(x = manufacturer, y = hwy)) +
geom_boxplot() +
coord_flip() +
xlab('Vehicle Manufacturer') +
ylab('Highway Fuel Efficiency (miles/gallon)') +
theme_classic()
## Vis 3
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()
## Vis 4
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')
## Vis 5
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()
Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.