Skip to content

Faceting Attributes

Mara Averick edited this page Nov 2, 2018 · 7 revisions

Note: The ggplot2 wiki is no longer maintained, please use the ggplot2 website instead!

Faceting Attributes

Return to opts() list

Base Plot

#create simple dataframe for plotting
xy <- data.frame(x = rep(1:10, times=3), y = rep(10:1, times=3), type = rep(LETTERS[1:2], each=5), type2 = rep(LETTERS[3:5], each=10))

#create base plot
plot <- ggplot(data = xy)+
geom_point(aes(x = x, y = y))+
facet_grid(type ~ type2)

#plot base plot
plot

strip.background (rect)

#
plot + theme(strip.background = element_rect(colour = 'purple', fill = 'pink', size = 3, linetype='dashed'))

strip.text.x (text)

#
plot + theme(strip.text.x = element_text(colour = 'red', angle = 45, size = 10, hjust = 0.5, vjust = 0.5, face = 'bold'))

strip.text.y (text)

#color doesn't work, need colour
plot + theme(strip.text.y = element_text(colour = 'red', angle = 45, size = 10, hjust = 0.5, vjust = 0.75, face = 'italic'))

#panel.margin ()

#big margins
plot + theme(panel.margin=unit(5 , "lines"))
#no margins
plot + theme(panel.margin=unit(0 , "lines"))

Note: The ggplot2 wiki is no longer maintained, please use the ggplot2 website instead!

Clone this wiki locally