1

I'm trying to use the scale_x_reverse() to change the order of my axis. I wnat in the top of my plot "AR-2010", "AR2011" and so on...

But when I use scale_x_reverse(), I got the following error

Error in -x : invalid argument to unary operator

Here is my code

ggplot()+ 
  geom_bar(data=data_iso[order(data_iso$sex,decreasing = T),],
           aes(x=yeariso,y=ratemort,fill=iso2,group=sex,alpha=sex,show.legend=F),
           color="transparent",stat="identity")+
  theme_bw()+
  scale_alpha_manual(values=c(0.4, 1)) +
  theme(legend.position="none")+
  labs(color = "Country",x="")+
  ylab(expression(Mortality~Rate~x~10^{5}))+
  scale_fill_manual("",
                    values=c("turquoise","green4","#FFDB6D","chocolate2","brown2",
                             "royalblue","mediumorchid1","pink","lightsalmon","firebrick4"))+
  geom_flag(data=df3,
            aes(x = a, y = b, country = c('ar', 'br', 'cl','co','cr','gt','mx','pe')), 
            size = 15)+
  scale_y_continuous(breaks = c(0,1e+5, 2e+5,3e+5), labels = c("0", "1", "2","3"), 
                     limits=c(14500, 315000), oob = rescale_none)+
  coord_flip()+
  scale_x_reverse()

Without the scale_x_reverse() I got the following graphic

enter image description here

Z.Lin
  • 28,055
  • 6
  • 54
  • 94
DR15
  • 647
  • 9
  • 17
  • 2
    `scale_x_reverse` is intended for continuous variables. You should reorder the factor levels of your variable to reverse a discrete scale. – teunbrand Oct 17 '19 at 16:31
  • Possible duplicate of [Reversed order after coord\_flip in R](https://stackoverflow.com/questions/34227967/reversed-order-after-coord-flip-in-r) – tjebo Oct 18 '19 at 13:00

0 Answers0