Re: migrate theme to 0.9.2.1

48 views
Skip to first unread message

Dennis Murphy

unread,
Nov 27, 2012, 8:23:25 PM11/27/12
to Rachael, ggp...@googlegroups.com
Hi:

Is this what you wanted? This should work for version 0.9.2 +. Some comments:

(1) modifyList() is no longer supported in the new theming system; use
the %+replace% operator instead.
(2) I added fill = NA to panel.border's properties because without it,
the fill color overwrites the graphics panel region and you get what
looks like an empty plotting region (although it really isn't).
(3) Notice how the element properties are modified inside theme()
rather than list(). This is consistent with the notion of replacing
specific element properties of theme_bw().
(4) The new theming system supports inheritance of properties, so it
is now only necessary to specify axis.text rather than both
axis.text.x and axis.text.y; they both inherit the property size = 15
from axis.text. Since there was only one common property in
axis.title.x and axis.title.y, I left them alone.

theme_boxplot2 <- function(base_size = 12)
{
theme_bw(base_size) %+replace%
theme(legend.key.size=unit(15,"points"),
legend.text=element_text(size=I(13)),
legend.key=element_blank(),
legend.title=element_blank(),
legend.position="none",
plot.margin=unit(c(0.25,2,0.25,2), "lines"),
panel.border=element_rect(colour='black', fill = NA),
panel.margin=unit(0,"lines"),
axis.ticks.length=unit(1,"mm"),
axis.ticks.margin = unit(0, "lines"),
axis.text=element_text(size=15),
axis.title.x=element_text(hjust=.55, vjust=-.01, size=17),
axis.title.y=element_text(size=17, angle=90,
hjust=.56, vjust=-.001),
panel.grid.major=element_blank(),
panel.grid.minor=element_blank(),
strip.text.x=element_text(size=14),
strip.background=element_rect(colour='black', fill='white')
)
}

ggplot(data=cars, aes(x=factor(speed), y=dist)) + geom_boxplot() +
xlab("speed") + ylab("distance") + theme_boxplot2()

Dennis

On Tue, Nov 27, 2012 at 10:44 AM, Rachael <rachael...@gmail.com> wrote:
> ggplot(data=cars, aes(x=factor(speed), y=dist)) + geom_boxplot() +
> xlab("speed") + ylab("distance") + theme_boxplot2()

Rachael

unread,
Nov 28, 2012, 3:26:54 PM11/28/12
to ggp...@googlegroups.com, Rachael
Great, this replicates what I had in 0.8.9. Thanks Dennis! 
Your comment #1 below leads me to ask if there is a comprehensive catalog of what has changed
or is no longer supported, and what the replacement should be?  I couldn't find anything about
modifyList() no longer being supported here :  https://github.com/hadley/ggplot2/blob/master/NEWS
Could you, or anyone else on the list, reference a better catalog of changes with solutions? 
Reply all
Reply to author
Forward
0 new messages