Graph Panel Attributes - brodieG/ggplot2 GitHub Wiki

Graph/Panel Attributes

Return to opts() list

Base Plot

#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

http://imgur.com/7y9Dr.png

panel.background (rect)

#color doesn't work, need colour
plot + theme(panel.background = element_rect(colour = 'purple', fill = 'pink', size = 3, linetype='dashed'))

http://imgur.com/zHpoh.png

panel.border (rect)

#color doesn't work, need colour
plot + theme(panel.border = element_rect(colour = 'purple', fill = 'pink', size = 3, linetype='dashed'))

http://imgur.com/WBx9r.png

panel.grid.minor (line)

plot + theme(panel.grid.minor = element_line(colour = 'red', size = 3, linetype = 'dashed'))

http://imgur.com/5RX9H.png

panel.grid.major (line)

plot + theme(panel.grid.major = element_line(colour = 'red', size = 3, linetype = 'dashed'))

http://imgur.com/w7EKT.png

panel.margin (unit)

#for facets
plot + theme(panel.margin = unit(2, "cm"))

See example on Facet Attributes Page

plot.background (rect)

#color doesn't work, need colour
plot + theme(plot.background = element_rect(colour = 'purple', fill = 'pink', size = 3, linetype='dashed'))

http://imgur.com/PJXWE.png

plot.title (text)

#Give the plot a title first
plot + theme(title = 'Graph Title')
# Play with title appearance
plot + theme(title = 'Graph Title', plot.title  = theme_text(colour = 'red', angle = 45, size = 10,hjust = 0.5, vjust = 0.5, face = 'bold'))

http://imgur.com/18NJW.png

plot.margin (unit)

#creates white space around plot (Must define all 4 sides in vector)
plot + theme(plot.margin = unit(c(5, 5, 5, 5), "cm"))

http://imgur.com/yWCVv.png