should themes alter the default scales?

44 views
Skip to first unread message

baptiste auguie

unread,
Mar 8, 2009, 12:43:16 PM3/8/09
to ggp...@googlegroups.com
Hi all,


In the process of making up dummy themes for the experimental
ggplot-add-ons page [*] I realised that the colour scale was not
really appropriate for some background colors. In contrast, lattice
has a different approach which is to set the default colours in
accordance to the theme (par.settings). In this view, a black and
white theme should perhaps set the colour scale to a grey scale.
Similarly, changing the base size for the text could affect the
default linewidth for the plot. What do you think?


baptiste

[*] http://ggplot-add-ons.r-forge.r-project.org/ : do feel free to join.

hadley wickham

unread,
Mar 9, 2009, 9:07:19 AM3/9/09
to baptiste auguie, ggp...@googlegroups.com
On Sun, Mar 8, 2009 at 10:43 AM, baptiste auguie
<bapt...@googlemail.com> wrote:
>
> Hi all,
>
>
> In the process of making up dummy themes for the experimental
> ggplot-add-ons page [*] I realised that the colour scale was not
> really appropriate for some background colors. In contrast, lattice
> has a different approach which is to set the default colours in
> accordance to the theme (par.settings). In this view, a black and
> white theme should perhaps set the colour scale to a grey scale.
> Similarly, changing the base size for the text could affect the
> default linewidth for the plot. What do you think?

I have thought about that too - maybe you'd also want to change the
default settings for the geoms (e.g. change the default point colour).
It would be fairly easy to do this yourself.

Hadley

--
http://had.co.nz/

baptiste auguie

unread,
Mar 9, 2009, 11:04:01 AM3/9/09
to hadley wickham, ggp...@googlegroups.com
Hi Hadley,

I can see how to change the default geoms and scales following the
manual, but what I fail to see is how I could include this
prescription in the definition of a theme.

The following doesn't do anything, I suppose because of some scope issue,

#library(ggplotpp)
mdf <- data.frame(x <- seq(0, 10), y=rnorm(x),
f=factor(rep(letters[1:2], each=3, length=length(x))))

a <- qplot(x, y, data=mdf, colour=f, geom=c("line", "point"), facets=f~.) +
theme_bw() + opts(title="theme_grey")

a # default

theme_bw2 <- function(...){
set_default_scale("colour", "discrete", "grey")
theme_bw(...)
}

a + theme_bw2() # still the default colours

Is there another way?


thanks,

baptiste

--

_____________________________

Baptiste Auguié

School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

Phone: +44 1392 264187

http://newton.ex.ac.uk/research/emag
______________________________

hadley wickham

unread,
Mar 10, 2009, 9:08:23 AM3/10/09
to baptiste auguie, ggp...@googlegroups.com
> I can see how to change the default geoms and scales following the
> manual, but what I fail to see is how I could include this
> prescription in the definition of a theme.

Sorry, I spoke to soon. I was thinking that you could just add on the
appropriate scales, but I had forgotten that of course you won't know
whether the variables will be discrete or continuous.

What you're trying to do is complicated because you want to affect
objects that don't exist yet. I don't see any way of doing this
locally, to affect just a single plot, but I presume most people are
doing theme_set(theme_bw()) rather + theme_bw(), so that's probably
not a huge problem. If I was you, I'd probably think about a new data
structure to describe the types of changes to scales, and then a
function to make those changes. Then separate your themes into two
parts, the part that works with the existing theme system, and the new
part, and write a function to update the global settings.

I'll think about how to make this easier from my end. I've been
thinking about a better way to preserve axis labels when you add a new
scale (it's currently rather complicated), and this would fit in
rather naturally.

Hadley

--
http://had.co.nz/

Reply all
Reply to author
Forward
0 new messages