Anna Zakrisson Braeunlich
2013-Sep-18 05:52 UTC
[R] ggplot2: changing shapes facet_grid - special case.
Hi, I want to change my geom.point shapes in facet grid. I have tried all sorts of solutions, but for some reason none seem to work. Something overrides the "normal" codes. I am stuck. I have attached the data to the mail. I want organism to have different shapes and then add a legend to the plot. thank you for your help! Code: Anaalldata <- read.table(file = "Annadata_2007_9_ISO_long.txt", header = TRUE, dec = ".") str(Anaalldata) names(Anaalldata) library(hexbin) library(grid) library(ggplot2) Anaalldata <- within(Anaalldata, fweek <- factor(week)) Anaalldata <- within(Anaalldata, fyear <- factor(year)) Anaalldata <- na.exclude(Anaalldata) names(Anaalldata) Summisodata11 <- ddply(Anaalldata, .(station, organism), summarise, mean = mean(deltancy), sd = sd(deltancy)) p <- ggplot(Anaalldata, aes(station, organism))+ geom_errorbar(data = Summisodata11, aes(ymin = mean - sd, y = mean, ymax = mean + sd), size = 1, width = 0.1, color = "black")+ geom_point(data = Summisodata11, aes(y = mean))+ scale_shape(solid = F)+ theme_bw() + theme(strip.background = element_blank())+ xlab("Station") + ylab(expression(paste("",delta^{15}, "N")))+ scale_y_continuous(limits=c(-3, 14), # Set y range breaks=-4:15*2) + geom_hline(yintercept=0, linetype=3) + #draws dotted line at 0 theme(strip.text.x = element_text(size = 20, colour="black", family="serif", angle=00)) + theme(strip.text.y = element_text(size = 20, colour="black", family="serif", angle=00)) + theme(axis.text.x = element_text(size = 20, colour="black", family="serif", angle=00)) + theme(axis.text.y = element_text(size = 17, colour="black", family="serif", angle=00)) + theme(axis.title.x = element_text(size=20, colour="black", family="serif", angle=00))+ theme(axis.title.y = element_text(size=20, colour="black", family="serif", angle=90))+ facet_wrap( ~ year) p Anna Zakrisson Braeunlich 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 at su.se Tel work: +49-(0)3091541281 Mobile: +49-(0)15777374888 LinkedIn: http://se.linkedin.com/pub/anna-zakrisson-braeunlich/33/5a2/51b><((((?>`?. . ? `?. .? `?. . ><((((?>`?. . ? `?. .? `?. .><((((?>`?. . ? `?. .? `?. .><((((?>-------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: Annadata_2007_9_ISO_long.txt URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130918/df5256cf/attachment.txt>
Does this questions help http://stackoverflow.com/questions/1478532/changing-shapes-used-for-scale-shape-in-ggplot2 ? It looks like it does but I don't have time at the moment to work it out with your code. Good luck John Kane Kingston ON Canada> -----Original Message----- > From: anna.zakrisson at su.se > Sent: Wed, 18 Sep 2013 05:52:33 +0000 > To: r-help at r-project.org > Subject: [R] ggplot2: changing shapes facet_grid - special case. > > Hi, > > I want to change my geom.point shapes in facet grid. I have tried all > sorts of solutions, but for some reason none seem to work. Something > overrides the "normal" codes. I am stuck. > I have attached the data to the mail. > I want organism to have different shapes and then add a legend to the > plot. > thank you for your help! > > Code: > > Anaalldata <- read.table(file = "Annadata_2007_9_ISO_long.txt", header > = TRUE, dec = ".") > str(Anaalldata) > names(Anaalldata) > library(hexbin) > library(grid) > library(ggplot2) > Anaalldata <- within(Anaalldata, fweek <- factor(week)) > Anaalldata <- within(Anaalldata, fyear <- factor(year)) > Anaalldata <- na.exclude(Anaalldata) > names(Anaalldata) > > Summisodata11 <- ddply(Anaalldata, .(station, organism), summarise, > mean = mean(deltancy), > sd = sd(deltancy)) > > p <- ggplot(Anaalldata, aes(station, organism))+ > > geom_errorbar(data = Summisodata11, aes(ymin = mean - sd, y = mean, > ymax = mean + sd), > size = 1, width = 0.1, color = "black")+ > geom_point(data = Summisodata11, aes(y = mean))+ > scale_shape(solid = F)+ > theme_bw() + > theme(strip.background = element_blank())+ > xlab("Station") + > ylab(expression(paste("",delta^{15}, "N")))+ > scale_y_continuous(limits=c(-3, 14), # Set y range > breaks=-4:15*2) + > geom_hline(yintercept=0, linetype=3) + #draws dotted line at 0 > theme(strip.text.x = element_text(size = 20, colour="black", > family="serif", angle=00)) + > theme(strip.text.y = element_text(size = 20, colour="black", > family="serif", angle=00)) + > theme(axis.text.x = element_text(size = 20, colour="black", > family="serif", angle=00)) + > theme(axis.text.y = element_text(size = 17, colour="black", > family="serif", angle=00)) + > theme(axis.title.x = element_text(size=20, colour="black", > family="serif", angle=00))+ > theme(axis.title.y = element_text(size=20, colour="black", > family="serif", angle=90))+ > facet_wrap( ~ year) > p > > Anna Zakrisson Braeunlich > 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 at su.se > Tel work: +49-(0)3091541281 > Mobile: +49-(0)15777374888 > LinkedIn: http://se.linkedin.com/pub/anna-zakrisson-braeunlich/33/5a2/51b > > ><((((?>`?. . ? `?. .? `?. . ><((((?>`?. . ? `?. .? `?. .><((((?>`?. . ? > `?. .? `?. .><((((?> > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.____________________________________________________________ GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at http://www.inbox.com/smileys Works with AIM?, MSN? Messenger, Yahoo!? Messenger, ICQ?, Google Talk? and most webmails
Hi Anna, It's not clear to me what you are trying to do. If you want different shapes for different organisms then you should map organism to shape, e.g., geom_point(data = Summisodata11, aes(y = mean, shape=organism)) Is that what you are looking for? If not please restate the question. Best, Ista On Wed, Sep 18, 2013 at 1:52 AM, Anna Zakrisson Braeunlich <anna.zakrisson at su.se> wrote:> Hi, > > I want to change my geom.point shapes in facet grid. I have tried all sorts of solutions, but for some reason none seem to work. Something overrides the "normal" codes. I am stuck. > I have attached the data to the mail. > I want organism to have different shapes and then add a legend to the plot. > thank you for your help! > > Code: > > Anaalldata <- read.table(file = "Annadata_2007_9_ISO_long.txt", header = TRUE, dec = ".") > str(Anaalldata) > names(Anaalldata) > library(hexbin) > library(grid) > library(ggplot2) > Anaalldata <- within(Anaalldata, fweek <- factor(week)) > Anaalldata <- within(Anaalldata, fyear <- factor(year)) > Anaalldata <- na.exclude(Anaalldata) > names(Anaalldata) > > Summisodata11 <- ddply(Anaalldata, .(station, organism), summarise, mean = mean(deltancy), > sd = sd(deltancy)) > > p <- ggplot(Anaalldata, aes(station, organism))+ > > geom_errorbar(data = Summisodata11, aes(ymin = mean - sd, y = mean, > ymax = mean + sd), > size = 1, width = 0.1, color = "black")+ > geom_point(data = Summisodata11, aes(y = mean))+ > scale_shape(solid = F)+ > theme_bw() + > theme(strip.background = element_blank())+ > xlab("Station") + > ylab(expression(paste("",delta^{15}, "N")))+ > scale_y_continuous(limits=c(-3, 14), # Set y range > breaks=-4:15*2) + > geom_hline(yintercept=0, linetype=3) + #draws dotted line at 0 > theme(strip.text.x = element_text(size = 20, colour="black", family="serif", angle=00)) + > theme(strip.text.y = element_text(size = 20, colour="black", family="serif", angle=00)) + > theme(axis.text.x = element_text(size = 20, colour="black", family="serif", angle=00)) + > theme(axis.text.y = element_text(size = 17, colour="black", family="serif", angle=00)) + > theme(axis.title.x = element_text(size=20, colour="black", family="serif", angle=00))+ > theme(axis.title.y = element_text(size=20, colour="black", family="serif", angle=90))+ > facet_wrap( ~ year) > p > > Anna Zakrisson Braeunlich > 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 at su.se > Tel work: +49-(0)3091541281 > Mobile: +49-(0)15777374888 > LinkedIn: http://se.linkedin.com/pub/anna-zakrisson-braeunlich/33/5a2/51b > >><((((?>`?. . ? `?. .? `?. . ><((((?>`?. . ? `?. .? `?. .><((((?>`?. . ? `?. .? `?. .><((((?> > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >