Luis Fernando GarcĂa
2015-Apr-09 06:11 UTC
[R] sorting means for plot in descending order
Dear R experts, I am newbie on the R use, now I want to sort my data by mean in a descending and not acending order (like I have done so far). If any of you could help me with this, it would be really appreciated! Thanks! Please find the script attached with the summary of the dat object pt<-summarySE(dat, measurevar="Time", groupvars=("Prey"))# pt Prey N Time sd se ci 1 cochinilla 10 351.6000 99.34103 31.41439 71.06429 2 hormiga 17 193.2353 92.50014 22.43458 47.55918 3 larva 18 259.0667 93.84009 22.11832 46.66558 4 termita 19 144.6316 65.30895 14.98290 31.47791 pt$Prey=c("Isopoda","Formicidae","Lepidoptera","Isoptera") bymean <- with(pt, reorder(Prey, Time, mean))# REordenar por promedio library(ggplot2) png(filename = "plotloxo1.png", width = 500, height = 500) e <- qplot(bymean, pt$Time,size=3)+theme(panel.grid.major element_blank(), panel.grid.minor = element_blank(), panel.background element_blank(), axis.line = element_line(colour = "black"))# e<-e+theme(legend.position="none")# e+ geom_errorbar(data = pt, aes(x = pt$Prey, y = pt$Time, ymin = pt$Time - pt$ci, ymax = pt$Time + pt$ci), colour = "black", width = 0.4, size=0.5)+ #A?adir barras de error xlab("Prey") + ylab("Time (Seconds)") + ggtitle("Total PM25 emissions") dev.off()# [[alternative HTML version deleted]]
> On 09 Apr 2015, at 08:11 , Luis Fernando Garc?a <luysgarcia at gmail.com> wrote: > > Dear R experts, > > I am newbie on the R use, now I want to sort my data by mean in a > descending and not acending order (like I have done so far). If any of you > could help me with this, it would be really appreciated!How about replacing "mean" with "function(x) -mean(x)" ? -pd> > Thanks! > > > Please find the script attached with the summary of the dat object > > > pt<-summarySE(dat, measurevar="Time", groupvars=("Prey"))# > > pt > > Prey N Time sd se ci > 1 cochinilla 10 351.6000 99.34103 31.41439 71.06429 > 2 hormiga 17 193.2353 92.50014 22.43458 47.55918 > 3 larva 18 259.0667 93.84009 22.11832 46.66558 > 4 termita 19 144.6316 65.30895 14.98290 31.47791 > > pt$Prey=c("Isopoda","Formicidae","Lepidoptera","Isoptera") > > bymean <- with(pt, reorder(Prey, Time, mean))# REordenar por promedio > > > library(ggplot2) > > png(filename = "plotloxo1.png", width = 500, height = 500) > > e <- qplot(bymean, pt$Time,size=3)+theme(panel.grid.major > element_blank(), panel.grid.minor = element_blank(), > panel.background > element_blank(), axis.line = element_line(colour = "black"))# > > > e<-e+theme(legend.position="none")# > e+ geom_errorbar(data = pt, aes(x = pt$Prey, y = pt$Time, ymin = pt$Time - > pt$ci, ymax = pt$Time + pt$ci), > colour = "black", width = 0.4, size=0.5)+ #A?adir barras > de error > xlab("Prey") + > ylab("Time (Seconds)") + > ggtitle("Total PM25 emissions") > > dev.off()# > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.-- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com