[R] boxplot with grouped variables

arun smartpink111 at yahoo.com
Sat May 11 18:41:03 CEST 2013


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.



----- Original Message -----
From: maggy yan <kiotoqq at gmail.com>
To: R-help at r-project.org
Cc: 
Sent: Saturday, May 11, 2013 11:40 AM
Subject: [R]  boxplot with grouped variables

my dataset looked like this in the beginning:

>Daten
      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

I need box plots for V2 with all combination of V1 and V3, so I deleted the
first row, and tried this:
boxplot(Daten$V2[Daten$V3=="m"])
but it does not work and I have no clue what I did wrong.
I'm thankful for any help!

    [[alternative HTML version deleted]]

______________________________________________
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.




More information about the R-help mailing list