Reordering the True and False Stack in R / ggplot2

When building boolean values ​​with qplot in ggplot2, False values ​​are always at the bottom, but most often I want True at the bottom to make it easier to read. Here is an example

y<-as.logical(rbinom(100,1,0.7)) x<-factor(rep(letters[1:2], each=50)) qplot(x,fill=y, geom='bar') 

How can I get the values ​​for TRUE at the bottom of the stack?

+4
source share
1 answer

If it’s convenient for you to convert to a factor, you can do this:

 yf <- factor(y, levels = c("TRUE", "FALSE")) qplot(x, fill = yf, geom = 'bar') 

I would just keep your original logical vector and use only the factor to build. It is difficult to understand which effects using a factor instead of a logical one may have the following flow.

+4
source

Source: https://habr.com/ru/post/1342376/


All Articles