[R] ggplot2 boxplot help

John Kane jrkrideau at inbox.com
Sun Aug 5 18:31:21 CEST 2012


Duh, I'm more dyslexic than usual obviously.  

John Kane
Kingston ON Canada


> -----Original Message-----
> From: ruipbarradas at sapo.pt
> Sent: Sun, 05 Aug 2012 17:07:38 +0100
> To: jrkrideau at inbox.com
> Subject: Re: [R] ggplot2 boxplot help
> 
> Hello,
> 
> Wasn't it supposed to be a boxplot?
> Anyway, the main problem seems to be a df format conversion prior to
> plotting.
> 
> dat2 <- data.frame(sample=rep(NA, 2*nrow(dat)))
> dat2$sample <- with(dat1, c(as.character(sample_1),
> as.character(sample_2)))
> dat2$value <- with(dat1, c(value_1, value_2))
> dat2
> 
> qplot(sample, value, data=dat2, geom="boxplot")
> 
> Hope this helps,
> 
> Rui Barradas
> 
> Em 05-08-2012 16:10, John Kane escreveu:
>> 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!
>> 
>> ______________________________________________
>> 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 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop!



More information about the R-help mailing list