0

I am trying to change the order of elements plotted in the slopegraph(below) generated in ggplot enter image description here My data set is

State.Name      value      Challenging          type
 Alabama      0.03549384        Crop           State
 Alabama      0.15840594     Pasture           State
 Alabama      0.06373341        Crop    Regional Mean
 Alabama      0.18004195     Pasture    Regional Mean
 Alabama      0.06763161        Crop    National Mean
 Alabama      0.11543352     Pasture    National Mean

My code is

plot<-ggplot(data = above df, aes(x = type, y = value, group = Challenging, colour= Challenging)) +
geom_line(size = 1) +
geom_point(size = 1)+ theme(legend.title=element_blank())+ theme_minimal()+  theme(legend.title = element_blank())+
labs(title=statenames[[i]])+ scale_color_manual(values =c("indianred4","yellow4"))+ 
theme(axis.title.x=element_blank())+ ylab("Opportunity in Challenging Soil Conditions (Mha)")

How do I edit above code such that the order of plotting in State, Regional Mean, National Mean instead of what the plot currently is i.e. National Mean, Regional Mean and State.

tg110
  • 401
  • 1
  • 3
  • 15

1 Answers1

1

One potential option would be to change the class of df$type and set the order prior to plotting. Like this:

df$type <- factor(df$type, levels = c('State', 'Regional Mean','National Mean')

Then do the ggplot code you already have.

Let me know if that helps!