[R] sorting means for plot in descending order (Luis Fernando Garc?a)
Manel Amado Martí
amado at cambrasabadell.org
Thu Apr 9 12:25:39 CEST 2015
Re:
Try with sort() function
sort(x, decreasing = FALSE, ...) As you can see, u can set the argument decreasing=TRUE, then, it'll sort by decreasing order.
For more details, call:
help(sort) under R console
Message: 23
Date: Thu, 9 Apr 2015 03:11:37 -0300
From: Luis Fernando Garc?a <luysgarcia at gmail.com>
To: r-help at r-project.org
Subject: [R] sorting means for plot in descending order
Message-ID:
<CANxP2S6U3u3NDum+uTvOaggqrsgT6EVWV3z70S_-xC7rAa_rWA at mail.gmail.com>
Content-Type: text/plain; charset="UTF-8"
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]]
Manel Amado i Martí
Cap d'Assessoria de Comerç Interior
amado at cambrasabadell.org
Tel. 93 745 12 63 · Fax 93 745 12 64
Av. Francesc Macià, 35 · 08206 Sabadell
Apt. corr. 119 · www.cambrasabadell.org
More information about the R-help
mailing list