0

So, I have this chunk:


stats %>%
  ggplot()+
  geom_col(mapping = aes(x = job_title, y = salary, fill = salary, scales = "free", ))+
  geom_smooth(mapping = aes(x = job_title, y = salary, col = "red"))+
  scale_y_log10()+
  scale_y_continuous(limits = c(0, 500000), breaks = c(0, 100000, 200000, 300000, 400000, 500000))+
  guides(color= guide_legend(), size = guide_legend())+
  xlab("Job Titles")+
  ylab("Salaries")+
  coord_flip()+
labs(title = "Salaries by Job Title",
     subtitle = "Averaged for all Experience Levels"
  
)
ggsave("avg_sal_allxp.png")

and it produces this plotted bar graph: Salary Bar graph/ggplot

....and no amount of manipulation with "y = reorder(salary, -salary)" etc will seem to solve this issue for me?

The issue is one of "Error: Discrete value supplied to continuous scale". Any help on how to reorder the salaries from highest to lowest here? Thank you all....again :)

Carlos Luis Rivera
  • 3,108
  • 18
  • 45
Bodhi
  • 1
  • 1
  • 1
    @TarJae they are using `coord_flip`, so it's the x-scale that is continuous. – Gregor Thomas Aug 10 '22 at 18:49
  • 1
    As per the marked duplicate, use `x = reorder(factor(job_title), salary)`. Because you are using `coord_flip`, you need to reorder, x, not y. (NB: coord_flip isn't needed anymore--not since ggplot version 3.3.0 in 2020--you can switch your x and y so they match with the plot you want and delete `coord_flip`.) – Gregor Thomas Aug 10 '22 at 18:49

0 Answers0