2

I'm finalizing a graph and hoping to change the order of two segments of my stacked bar graph.

Current Stacked Bar Chart

I have tried both the forcats::fct_rev() solution as offered in documentation and Reverse stacked bar order as well as position_fill(reverse = TRUE) in my geom_bar argument.

Simplified code:
plot2<-ggplot(r_4,aes(x=V1,y=V3,fill=V2))+
  coord_flip()+
  geom_bar(stat="identity")
Data:
structure(list(V1 = structure(c(1L, 1L), .Label = "Reagan", class = "factor"), 
    V2 = structure(1:2, .Label = c("Case-Based", "Term-Based"
    ), class = "factor"), V3 = structure(c(2L, 1L), .Label = c("0.36", 
    "0.64"), class = "factor")), .Names = c("V1", "V2", "V3"), row.names = c(NA, 
-2L), class = "data.frame")

I would like the smaller piece ("Term-Based") on the left and the larger piece ("Case-Based") on the right.

Thank you!

KLB
  • 57
  • 7

1 Answers1

1

edit: change V3, not V2

As akrun commented, change factor levels, then it should work:

r_4$V3 <- factor(c("0.36", "0.64"))

plot2<-ggplot(r_4,aes(x=V1,y=V3,fill=V2))+
  coord_flip()+
  geom_bar(stat="identity")
heds1
  • 3,203
  • 2
  • 17
  • 32
  • Doesn't work. I've tried this (and just tried again). It flips the coloring, but not the actual area. I even manually changed the dataset, too. – KLB Jun 07 '19 at 03:35
  • Just got it to work. I had to reorder V3 rather than V2. Thanks for the jumpstart. – KLB Jun 07 '19 at 03:38