Anna Zakrisson Braeunlich
2013-Nov-13 10:05 UTC
[R] ggplot2: geom_boxplot. Mapping aes factor but with different color scale and hatching
Dear all,
I have a geom_boxplot where I have the boxes colored according to a factor. The
color scale given is very lovely and colorful, but I need it in grayscale. how
do I change this?
I also am worried that the grayscale may be too similar (black/white is also not
an option as in my real data I have much more than the two dummy factors I have
put in the dummy data). Therefore, I would like to hatch the boxes also mapped
according to the factors (see script and data below). How can I accomplish this?
Also, I have a problem that I though would be easy to solve over Stack Overflow,
but turn out to be more complex. i would like to have one of my legend titles in
italics. Sounds basic, but can't solve it somehow. I have marked in the
script below where this is.
Many thank's for your help!
Dummydata:
mydata <- data.frame(
D15N = c(runif(100, min = -2), runif(100), runif(100, max = 2), runif(100)),
Year = rep(c('2007', '2008'), each = 100),
SampleType = rep(c('cyano', 'seston'), each = 200),
Station = sample(c('B1', 'H2', 'H3', 'H4'),
400, replace = TRUE),
Week = sample(c('19', '21', '23', '25'), 400,
replace = TRUE))
library(ggplot2)
Summdata <- ddply(mydata, .(Week, SampleType, Year, Station), summarise,
median = median(D15N))
ggplot(Summdata, aes(x = Station, y = median)) +
(mapping=aes(group=interaction(Station, SampleType)))+
theme_bw() +
geom_boxplot(mapping=aes(fill=SampleType), #I would like to have grayscale and
hatched - how?
outlier.shape=1,
outlier.size=3)+
theme(strip.background = element_blank())+
ylab(expression(paste("",delta^{15}, "N")))+
xlab("Station") +
scale_shape(solid = FALSE)+
geom_hline(yintercept=0, linetype=3)+
scale_fill_discrete(guide = guide_legend("my stuff"),
labels=c("cyanobacteria", "seston"))
#if I wanted to have "seston" in italics - how would I do that?
with kind regards
Anna Zakrisson
PhD student
Department of Ecology, Environment and Plant Sciences
Stockholm University
Svante Arrheniusv. 21A
SE-106 91 Stockholm
Sweden/Sverige
Lives in Berlin.
For paper mail:
Katzbachstr. 21
D-10965, Berlin - Kreuzberg
Germany/Deutschland
E-mail: anna.zakrisson@su.se
Tel work: +49-(0)3091541281
Mobile: +49-(0)15777374888
LinkedIn: http://se.linkedin.com/pub/anna-zakrisson-braeunlich/33/5a2/51b
><((((º>`•. . • `•. .• `•. . ><((((º>`•. . • `•. .• `•.
.><((((º>`•. . • `•. .• `•. .><((((º>
[[alternative HTML version deleted]]