[R] ggplot2 boxplot help

John Kane jrkrideau at inbox.com
Sun Aug 5 17:10:17 CEST 2012


Please use dput() to supply sample data.  

I think this does something like what you want.
####===================================================###
ibrary(ggplot2)
library(reshape2)

 dat1<-read.table(text="
sample_1 sample_2     value_1  value_2
N                  C               1.9268400 36.77590
N                  C               0.1817890  5.58835
N                  C                0.2309000 7.54035
N                 C                  0.0294559 1.50886
N                  C                 0.4678610 14.75560
 N                 C                 10.7258000 92.13150",
       sep="",header=TRUE)


bb  <-  melt(dat1)

p  <-  ggplot(bb  , aes(variable, value, fill =as.factor(value )  )) + 
                      geom_bar(stat= "identity", position = "dodge")  +
                       scale_fill_discrete(name = "Fancy Title") +
                      scale_x_discrete(breaks=c("value_1", "value_2"), labels=c("Sample 1", "Sample 2"))
p
##========================================================##

John Kane
Kingston ON Canada


> -----Original Message-----
> From: alexpadron1082 at gmail.com
> Sent: Sat, 4 Aug 2012 14:21:49 -0700 (PDT)
> To: r-help at r-project.org
> Subject: [R] ggplot2 boxplot help
> 
> Hello,
> 
> I have a data set that looks like this:
> 
>    name      G-ID     test_id     g-id g
> 1 00077464 C_068131 C_068131 OC_068131    -
> 2 00051728 C_044461 C_044461 OC_044461    -
> 3 00058738 C_050343 C_050343 OC_050343    -
> 4 00059239 C_050649 C_050649 OC_050649    -
> 5 00001761 C_000909 C_000909 OC_000909    -
> 6 00005119 C_002752 C_002752 OC_002752    -
>      locs                            sample_1 sample_2     value_1
> value_2
> 1 37316550-37317847   N                  C               1.9268400
> 36.77590
> 2 27058468-27060176   N                  C               0.1817890
> 5.58835
> 3 4761739-4763268        N                  C                0.2309000
> 7.54035
> 4  14565311-14567393   N                 C                  0.0294559
> 1.50886
> 5  38670994-38675694   N                  C                 0.4678610
> 14.75560
> 6   48362804-48380794   N                 C                 10.7258000
> 92.13150
> 
> 
> 
> In this dataset, sample_1 corresponds to value_1 and sample_2 corresponds
> to
> value_2. How can I graph this in ggplot2's boxplot function? I am not
> quite
> sure how to tell R that sample_1 and sample_2 columns correspond to
> value_1
> and value_2 using ggplot2.
> 
> Can anyone shed some light on this?
> 
> Thanks.
> 
> 
> 
> --
> View this message in context:
> http://r.789695.n4.nabble.com/ggplot2-boxplot-help-tp4639187.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> 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.

____________________________________________________________
FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family!
Visit http://www.inbox.com/photosharing to find out more!



More information about the R-help mailing list