0

enter image description hereSo...it's a basic graph, but I am confused as to why my numeric y-axis is showing up in a weird order. My other two graphs it shows in order, how can I fix this?

ggplot(EHHI) +
    geom_col(aes(x = Education.Level, y = Total.House.Hold.Income), color = "black") +
labs(title = "Total Household Income by Education Level",
         x = "Education Level",
         y = "Total Household Income",
         caption="caption goes here") +
theme_bw() +
  theme(title=element_text(size=30, hjust = 0.5, face = "bold", color = "black"),
         axis.text=element_text(size=20)) +
scale_x_discrete(limits = c("Elementary Junior High", "High School or Diploma", "Some College", "Associates Degree", "Four Year College Degree", "Some Graduate School", "Graduate Degree"))
structure(list(Education.Level = c("Elementary Junior High", 
"High School or Diploma", "Some College", "Associates Degree", 
"Four Year College Degree", "Some Graduate School"), Average.House.Hold.Income = c("13,527 ", 
"17,528 ", "19,808 ", "21,489 ", "27,657 ", "28,105 "), Total.House.Hold.Income = c("81,162 ", 
"2,366,293 ", "5,506,559 ", "2,449,768 ", "13,994,378 ", "2,107,851 "
), Count = c(6L, 135L, 278L, 114L, 506L, 75L)), row.names = c(NA, 
6L), class = "data.frame")
cd19_ bri
  • 23
  • 3
  • 1
    Your `Total.House.Hold.Income` is now character, not numeric. Change type of variable to numeric. – Park Feb 21 '23 at 05:24
  • ahhhh, that makes more sense, how can I do it quickly? In my excel sheet the column shows as a number, so I'm not sure what I need to do to fix it – cd19_ bri Feb 21 '23 at 05:26
  • ok, I changed it to general in my excel sheet and now it is showing up in order, but they are showing up in exponential form.... – cd19_ bri Feb 21 '23 at 05:33

1 Answers1

0

You may try

Base R

EHHI$Total.House.Hold.Income <- as.numeric(gsub(",", "", EHHI$Total.House.Hold.Income))

ggplot(EHHI) +
  geom_col(aes(x = Education.Level, y = Total.House.Hold.Income), color = "black") +
  labs(title = "Total Household Income by Education Level",
       x = "Education Level",
       y = "Total Household Income",
       caption="caption goes here") +
  theme_bw() +
  theme(title=element_text(size=30, hjust = 0.5, face = "bold", color = "black"),
        axis.text=element_text(size=20)) +
  scale_x_discrete(limits = c("Elementary Junior High", "High School or Diploma", "Some College", "Associates Degree", "Four Year College Degree", "Some Graduate School", "Graduate Degree"))

dlpyr

library(dplyr)
EHHI %>%
  mutate(Total.House.Hold.Income = as.numeric(gsub(",", "", Total.House.Hold.Income))) %>%
  ggplot() +
  geom_col(aes(x = Education.Level, y = Total.House.Hold.Income), color = "black") +
  labs(title = "Total Household Income by Education Level",
       x = "Education Level",
       y = "Total Household Income",
       caption="caption goes here") +
  theme_bw() +
  theme(title=element_text(size=30, hjust = 0.5, face = "bold", color = "black"),
        axis.text=element_text(size=20)) +
  scale_x_discrete(limits = c("Elementary Junior High", "High School or Diploma", "Some College", "Associates Degree", "Four Year College Degree", "Some Graduate School", "Graduate Degree"))

Note that Total.House.Hold.Income's scale is pretty weird.

Park
  • 14,771
  • 6
  • 10
  • 29