You may also try:
library(ggplot2)
p<-ggplot(dat2New,aes(x=combin,y=value))+geom_boxplot()+facet_wrap(~V3,scales="free_x",ncol=2)
p+stat_summary(fun.y=mean,shape=2,col="red",geom="point")
A.K.
----- Original Message -----
From: maggy yan <kiotoqq at gmail.com>
To: R-help at r-project.org
Cc:
Sent: Saturday, May 11, 2013 8:57 PM
Subject: [R]? need means on all boxplots, but only half of them got that
I tried to draw a point on all boxplots for their means, I did:
boxplot( Daten$weight~interaction(Daten$Dosis,Daten$sex, drop=TRUE))
means<-tapply( Daten$weight, Daten$Dosis, mean)
points(means, pch=5, col="red", lwd=5)
but only the boxplots for male got that point on them, its really weird
because I don't think that I separated the sex in the codes above
----- Original Message -----
From: arun <smartpink111 at yahoo.com>
To: maggy yan <kiotoqq at gmail.com>
Cc: R help <r-help at r-project.org>
Sent: Saturday, May 11, 2013 12:41 PM
Subject: Re: [R] boxplot with grouped variables
Hi,
Try this:
dat1<- read.table(text="
??? V1????? V2???????? V3
1? Dosis Gewicht Geschlecht
2????? 0??? 6.62????????? m
3????? 0??? 6.65????????? m
4????? 0??? 5.78????????? m
5????? 0??? 5.63????????? m
6????? 1??? 6.78????????? m
7????? 1??? 6.45????????? m
8????? 1??? 5.68????????? m
9????? 1??? 5.89????????? m
10????? 0??? 6.72????????? f
11????? 0??? 6.75????????? f
12????? 0??? 5.89????????? f
13????? 0??? 5.78????????? f
14????? 1??? 6.89????????? f
15????? 1??? 7.75????????? f
16????? 1??? 4.89????????? f
17????? 1??? 5.89????????? f
",header=TRUE,sep="",stringsAsFactors=FALSE)
dat2<-dat1[-1,]
boxplot(as.numeric(dat2$V2)[dat2$V3=="m"])# works
dat2$V2<- as.numeric(dat2$V2)
library(ggplot2)
library(plyr)
library(reshape2)
?dat2New<-mutate(melt(dat2,id.var=c("V1","V3")),combin= as.character(interaction(V1,V3,sep="_")))
ggplot(dat2New,aes(x=combin,y=value))+geom_boxplot()
#or
ggplot(dat2New,aes(x=combin,y=value))+geom_boxplot()+facet_wrap(~V3,scales="free_x",ncol=2)
A.K.
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.