ggplot2 - How to reorder in R -


i using code:

z <- data.frame(ins = factor(c("d", "c",    "a",    "e",  "f",  "b")),             percent = c(2.48,   4.55,   15.16,  16.47,  21.17,  40.17))  ggplot(data=z, aes(x=ins, y=percent)) + geom_bar(stat="identity")+   geom_bar(colour="na", fill="slateblue3", stat="identity") +    guides(fill=false) +   coord_flip() +   xlab("year") + ylab ("procent (%)") +   ggtitle("people using computers         - 2014 -") +   theme(axis.text.x = element_text(angle = 90, hjust = 1, colour='black'))+   theme(panel.background = element_rect(fill = 'white', colour = 'white')) 

when run plot, r reorders values as: a, b, c, d, e, f , not order gave: d, c, a, e, f, b, corresponds increasing order: 2.48 40.17. can keep order want? 10x

since question "how reorder", think answer is

z$ins <- reorder( z$ins, z$percent ) 

which reorders factor , thus, data.frame (not graphical presentation), , in flexible manner (as opposed re-assigning levels explictly).


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -