-
Notifications
You must be signed in to change notification settings - Fork 2k
Graph Panel Attributes
Mara Averick edited this page Nov 2, 2018
·
16 revisions
Note: The ggplot2 wiki is no longer maintained, please use the ggplot2 website instead!
#create simple dataframe for plotting
xy <- data.frame(x=1:10, y=10:1)
#create base plot
plot <- ggplot(data = xy)+
geom_point(aes(x = x, y = y))
#plot base plot
plot
#color doesn't work, need colour
plot + theme(panel.background = element_rect(colour = 'purple', fill = 'pink', size = 3, linetype='dashed'))
#color doesn't work, need colour
plot + theme(panel.border = element_rect(colour = 'purple', fill = 'pink', size = 3, linetype='dashed'))
plot + theme(panel.grid.minor = element_line(colour = 'red', size = 3, linetype = 'dashed'))
plot + theme(panel.grid.major = element_line(colour = 'red', size = 3, linetype = 'dashed'))
#for facets
plot + theme(panel.margin = unit(2, "cm"))
See example on Facet Attributes Page
#color doesn't work, need colour
plot + theme(plot.background = element_rect(colour = 'purple', fill = 'pink', size = 3, linetype='dashed'))
#Give the plot a title first
plot + labs(title = 'Graph Title')
# Play with title appearance
plot + labs(title = 'Graph Title') + theme(plot.title = element_text(colour = 'red', angle = 45, size = 10,hjust = 0.5, vjust = 0.5, face = 'bold'))
#creates white space around plot (Must define all 4 sides in vector)
plot + theme(plot.margin = unit(c(5, 5, 5, 5), "cm"))