[R] How to select a subset data to do a barplot in ggplot2

arun smartpink111 at yahoo.com
Thu Dec 13 17:36:50 CET 2012


Hi,

May be this:
p<-ggplot(subset(dat1,STATUS!="nosperm"),aes(x=FID))
 p+geom_bar(aes(x=factor(FID),y=..count..,fill=STATUS))
A.K.




----- Original Message -----
From: Yao He <yao.h.1988 at gmail.com>
To: r-help at r-project.org
Cc: 
Sent: Thursday, December 13, 2012 7:38 AM
Subject: [R] How to select a subset data to do a barplot in ggplot2

Hi,everybody

I have a dataframe like this

FID IID STATUS
1    4621    live
1    4628    dead
2    4631    live
2    4632    live
2    4633    live
2    4634    live
6    4675    live
6    4679    dead
10    4716    dead
10    4719    live
10    4721    dead
11    4726    live
11    4728    nosperm
11    4730    nosperm
12    4732    live
17    4783    live
17    4783    live
17    4784    live

I just want a barblot to count "live" or "dead" in every "FID", and fill
the bar with different colour.

I try these codes:

p<-ggplot(data,aes(x=FID));
p+geom_bar(aes(x=factor(FID),y=..count..,fill=STATUS))

But how could I exclude "nosperm" or other levels just in the use of
ggplot2 without generating another dataframe

Thanks a lot

Yao He
—————————————————————————
Master candidate in 2rd year
Department of Animal genetics & breeding
Room 436,College of Animial Science&Technology,
China Agriculture University,Beijing,100193
E-mail: yao.h.1988 at gmail.com <mingxie at vt.edu>
——————————————————————————

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