squid
unread,May 8, 2009, 5:55:24 AM5/8/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ggplot2
Hi,
I can't find my old post from Tue, Apr 28, 2009 at 8:39 PM
subject Re: split plot and vertical shaded background
in which Hadley suggested I try geom_rect to put some background
shading in particular rectangular regions of my plot. I've been
playing with it and have discovered it is important to plot the
rectangles BEFORE the data if you want the data to show up on top of
the rectangles. This makes sense in the 'layers' philosophy, but took
me a minute to figure out.
Now I'm struggling with trying to find a way in which the shaded
rectangle is transparent to the background grids as well. My x axis
runs from 0 to 60million. I need background shading in two places on
that plot (see geom_rect below). This code works well but I can no
longer see the grid behind denoting the breaks on the x and y axes.
ggplot(data=subset(all, (Arm=="2R") &(x.m.cov >20000)&(x.s.cov
>20000)) , aes(block)) +
geom_rect(aes(xmin=18930000,xmax=26764357, ymin= 0, ymax=max
(ms.x.shared) ), fill="grey80")+
geom_rect(aes(xmin=26764357,xmax=31450000, ymin= 0, ymax=max
(ms.x.shared) ), fill="grey70")+
geom_line(aes(y = ms.x.shared, colour = "Shared polymorphisms\n
between M and S\n"), size= .75) +
geom_line(aes(y = ms.x.fixed, colour = "Fixed differences\n between M
and S\n"), size= .75) +
labs(x = "2R (in Mb)", y = "Proportion of sites") + opts
(axis.title.x=theme_text(size=14), axis.title.y=theme_text
(size=14,angle = 90))+
opts(title = "Polymorphisms and fixed differences in 50kb windows,
minimum coverage per window=20kb") + opts(plot.title = theme_text
(size=16)) +
scale_colour_discrete("Site type") +
scale_x_continuous(breaks=c
(0,10000000,20000000,30000000,40000000,50000000,60000000), labels=c
("0\nTELOMERIC", "10\n", "20\n","30\n", "40\n", "50\n",
"60\nCENTROMERIC")) +
scale_colour_brewer(palette="Dark2") +
opts(axis.text.x = theme_text(colour = "black", vjust=1))+
opts(axis.text.y = theme_text(colour = "black", hjust=1))
Is there something like a 'transparency' function for geom_rect so
that I might still be able to see the horizontal and vertical white
lines that grid the background of all plots?
Additionally, is there something like "free_y" for the ymax entry? I
have chosen the max of my data which is easy here with only two
variables plotted, but if I had ten variables, I'd have to figure out
which had the maximum value for each plot.
Thanks, again.