-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Editing raw grid objects from a ggplot
baptiste edited this page Sep 2, 2010
·
7 revisions
- save the plot as a grob
- locate the particular grob in the gTree
- call grid.edit() with the gPath constructed from the information of step #2
A simple example goes like this, (adpated from r-help, http://finzi.psych.upenn.edu/Rhelp08/2009-May/199976.html)
library(ggplot2)
p <- # minimal example
qplot(0,0, geom="blank")+ annotate("text",0,0,label="alpha")
p
g <- # store the plot as a grob
ggplotGrob(p)
# structure of the grob
# grid.ls(g) # rather large!
# find a particular grob in the gTree
# grid.ls(grob=F, view=T)
grid.ls(getGrob(g,"texts", grep = T))
grid.edit(gPath("texts.gTree", "GRID.text"), grep=TRUE,
gp=gpar(col="pink"))
grid.edit(gPath("texts.gTree", "GRID.text"), grep=TRUE,
label=expression(alpha^2), gp=gpar(col="red"))