[R] sorting means for plot in descending order

Luis Fernando García luysgarcia at gmail.com
Thu Apr 9 08:11:37 CEST 2015


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



More information about the R-help mailing list