r - How to order factor variables in ggplot -



r - How to order factor variables in ggplot -

i order plant growth form factor variables on x-axis decreasing slope value rather alphabetically. have tried reorder() function without success.

slope = c(1.0508194, 0.9406335, 1.1271495, 1.0496251, 0.9874658, 0.9358822, 0.8621570, 1.0403310, 1.0380560, 1.0401669) veg3 <- data.frame(plant_growth_form = as.factor(c("fern", "fern ally", "grass", "herb","herbaceous climber", "herbaceous shrub", "tree sapling", "undet", "woody climber", "woody shrub"))) ggplot(veg3, aes(x = plant_growth_form, y = slope)) + geom_point(cex=2) + xlab("growth form") + ylab("slopes") + ylim(0,2) + theme_bw() + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())

a reproducible info subset generated dput() can found at: how compute standard errors predicted data

for me code reorder() works expected.

ggplot(veg3, aes(x = reorder(plant_growth_form,-slope), y = slope)) + geom_point(cex=2) + xlab("growth form") + ylab("slopes") + ylim(0,2) + theme_bw() + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())

r plot ggplot2 r-factor

Comments

Popular posts from this blog

c# - ASP.NET MVC Sequence contains no matching element -

java - Parsing XML, skip certain tags -

rest - How to invalidate user session on inactivity in a stateless server? -