0

i have a large dataframe that looks like this:

df <- data.frame(wealth = c(low, med, high), income = c(50000, 100000, 150000))

when I code a ggplot and enter wealth as an x or y variable, it lists high first since it is alphabetical.

how can I manual change the order that it lists the wealth variable in ggplot to low, med, high?

taimishu
  • 37
  • 6

1 Answers1

1
library(ggplot2)
df <- data.frame(wealth = c("low", "med", "high"), income = c(50000, 100000, 150000))
df$wealth_f <- factor(df$wealth, levels = c("low", "med", "high"))
ggplot(data = df, aes(x = wealth_f, y = income)) + geom_col()

enter image description here

Wimpel
  • 26,031
  • 1
  • 20
  • 37