bugs in ggplot2 book

7 views
Skip to first unread message

Wincent

unread,
Jun 8, 2009, 3:42:24 AM6/8/09
to ggplot2
In the last chapter, there are such codes (http://had.co.nz/ggplot2/
book/grid.r)

p <- qplot(wt, mpg, data=mtcars, colour=cyl)
# Get the plot grob
grob <- ggplotGrob(p)
# Modify in place
grob <- geditGrob(grob, gPath("strip","label"), gp=gpar
(fontface="bold"))

# Draw it
grid.newpage()
grid.draw(grob)

After modification of grob, it becomes NULL, which is obviously a
mistake, right?

hadley wickham

unread,
Jun 17, 2009, 6:21:19 PM6/17/09
to Wincent, Paul Murrell, ggplot2
Hi Wincent,

Wow, that's a terrible example, but it illustrates that geditGrob will
return NULL if it can't find the named grob (I'm pretty sure I
complained to Paul about this but I forgot what the outcome was).

A better illustration is

p <- qplot(wt, mpg, data=mtcars, colour=cyl)
grob <- ggplotGrob(p)
grob2 <- geditGrob(grob, gPath("legend.text"), gp=gpar(fontface = "bold"))

grid.newpage()
grid.draw(grob2)

I'll add this to the book errata.

Hadley
--
http://had.co.nz/
Reply all
Reply to author
Forward
0 new messages