Introduction to Data Visualization with ggplot2
Rick Scavetta
Founder, Scavetta Academy
z <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) +
geom_jitter(alpha = 0.6) +
scale_x_continuous("Sepal Length (cm)", limits = c(4,8), expand = c(0,0)) +
scale_y_continuous("Sepal Width (cm)", limits = c(1.5,5), expand = c(0,0)) +
scale_color_brewer("Species", palette = "Dark2", labels = c("Setosa", "Versicolor", "Virginica"))
z + theme(text = element_text(family = "serif", size = 14),
rect = element_blank(),
panel.grid = element_blank(),
title = element_text(color = "#8b0000"),
axis.line = element_line(color = "black"))
theme_iris <- theme(text = element_text(family = "serif", size = 14),
rect = element_blank(),
panel.grid = element_blank(),
title = element_text(color = "#8b0000"),
axis.line = element_line(color = "black"))
z + theme_iris
m <- ggplot(iris, aes(x = Sepal.Width)) +
geom_histogram(binwidth = 0.1,
center = 0.05)
m
m +
theme_iris
m +
theme_iris +
theme(axis.line.x = element_blank())
Use theme_*()
functions to access built-in themes.
z +
theme_classic()
Use theme_*()
functions to access built-in themes.
z +
theme_classic() +
theme(text = element_text(family = "serif"))
Use the ggthemes
package for more functions.
library(ggthemes)
z +
theme_tufte()
original <- theme_update(text = element_text(family = "serif", size = 14),
rect = element_blank(),
panel.grid = element_blank(),
title = element_text(color = "#8b0000"),
axis.line = element_line(color = "black"))
z
theme_set(original)
# Alternatively
# theme_set(theme_grey())
Introduction to Data Visualization with ggplot2