1

I am attempting to switch the plotted bars so the first column is for Budgeted and the second column in for Actual. Any help is much appreciated.

Picture

This is my code.

library(tidyverse)
library(ggplot2)
library(dplyr)
library(scales)

Mississppi <-as.data.frame(R_test_8)
head(Mississppi)


ggplot() + geom_col(data = Mississppi, aes( x = Ship, y = Mandays , fill = Type), position = "dodge") +  geom_point() +
 scale_y_continuous(labels = label_number (suffix = " K", scale = 1e-3), limits = c(0, 400000), breaks = seq(0, 400000, by = 50000)) + geom_hline(yintercept = 200000, color = "#7c7d81", linetype = 2) + scale_fill_manual(values = c("#6b9bb1", "#102031")) +  geom_point() +
  theme_classic() + theme(axis.title.x = element_blank(), axis.title.y = element_blank()) + ggtitle("Days of Labor (Thousands)")

Peter
  • 11,500
  • 5
  • 21
  • 31
tatertot2
  • 11
  • 2
  • Please make your question reproducible: include the output of `dput(R_test_8)` in the question. – Peter Jun 02 '23 at 21:07
  • `Mississppi2 <- Mississppi |> mutate(Type = fct_rev(Type))` and then use Mississppi2. That will make the Type variable be a factor that is in the opposite order of its current default alphabetical order. – Jon Spring Jun 02 '23 at 21:20
  • 1
    just about (or perhaps "all"?) questions on SO that ask about "order of axis", "order of plots", or "order of legend" are resolved with the use of `factor` and using its `levels=` argument – r2evans Jun 02 '23 at 21:27
  • see ggplot2/axis-order: https://stackoverflow.com/q/3253641/3358272, https://stackoverflow.com/q/12774210/3358272, https://stackoverflow.com/q/18401931/3358272; ordering with groups https://stackoverflow.com/q/44350031/3358272 – r2evans Jun 02 '23 at 21:28
  • Welcome to SO, tatertot2! This question will be closed as a duplicate, please look at the links I provided and learn how to apply it to your data (which we don't have). If after you do that you still cannot figure it out, please make this question [reproducible](https://stackoverflow.com/q/5963269) by [edit]ing it and including sample data (perhaps using `dput` or `data.frame`, see that link), and show the updated code with any warnings/errors. Once that's done, @-ping me and we'll sort out what is different or such. Thanks and good luck! – r2evans Jun 02 '23 at 21:30

0 Answers0