Order of levels in ggplot2

Hi, I struggle to order the variables on the 'final' y-axis as I would like to? I want 'EPP'to be the first.

Thank you

ggplot(pos7,aes(x=factor(EPG,levels=c("EFFD","Greens/EFA","GUE/NGL","ALDE","ECR","S&D","EPP")),y=value,color=EPG,weight=seats))+
  geom_jitter(position=position_jitter(width=0.2,height=0),alpha=0.8)+
  geom_boxplot(alpha=0,show.legend=FALSE,lwd=1)+
  scale_color_manual(limits=c("EPP","S&D","ECR","ALDE","GUE/NGL","Greens/EFA","EFDD"),
                     values=c("#fcdd22","#fc1414","#106da8","#ec008c","#c6262c","#44911d","#00abbc"))+
  guides(color=guide_legend(""))+
  theme(legend.position="bottom", 
        axis.text.y=element_blank(),
        axis.ticks=element_blank())+
  labs(x="",y="",title="",subtitle=expression(paste("7"^"th", " European Parliament (Chapel Hill Expert Survey 2010)")))+
  facet_grid(variable~.)+
  coord_flip()
#> Error in ggplot(pos7, aes(x = factor(EPG, levels = c("EFFD", "Greens/EFA", : could not find function "ggplot"

Hi Jakub!

To achieve that you need to change the order of EPG's levels, the plotting order follows the level order. In your case it seems like EPP is the last level of EPG, so try messing around with that.

You can find mode info on it here: https://www.r-graph-gallery.com/22-order-boxplot-labels-by-names.html

Oh, and for future reference, it's advisable to provide a reprex along with your question. It makes it easier to help out :slight_smile:

Cheers!

2 Likes

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.