g is a gtable object. You can inspect it with the following:
# Show the structure of the gtable object, but don't recurse into sub-components
str(g, max.level=1)
# Print the data frame recording layout
g$layout
# Get the list of grobs in the gtable
g$grobs
# Get a 1x1 gtable that contains just the title
g[2,4]
This code will have the effect you're looking for. It might be worth
thinking about how to modify the gtable API to make this sort of
access easier.
library(ggplot2)
library(grid)
library(gtable)
p <- qplot(wt, mpg, data = mtcars, colour = cyl, main = "Title text")
g <- ggplotGrob(p)
# Get index of the title grob
idx <- which(g$layout$name == "title")
# Modify the title grob and save it back
g$grobs[[idx]] <- editGrob(g$grobs[[idx]], gp = gpar(fontface =
"italic", col="red"))
grid.draw(g)
It would also be nice to be able to do something like
grid.ls() on a
gtable and get back a useful result.
-Winston
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example:
>
https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email
ggp...@googlegroups.com
> To unsubscribe: email
ggplot2+u...@googlegroups.com
> More options:
http://groups.google.com/group/ggplot2