0

I'm trying to plot a basic bar chart outlining the count of values for each year. I'm not sure why the 'Year' is displaying in random order on the x axis? I would like to order the year by their sequential order.

Thanks!

Here is the code and the output plot. I have tried arranging the dataframe by Year and it did for the dataframe but doesn't change anything for the plot. Year is currently set as a "factor" data type.

data %>% 
  ggplot(aes(x=Year)) +
  geom_bar()+
  xlab("Year") +
  ylab("Count")+
  theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1))
Cindy
  • 9
  • 1
  • 2
    Welcome @Cindy. What format is your `Year` column? Is it a character or factor? – Scransom Nov 11 '22 at 03:33
  • 3
    Generally it helps people to answer you if you include some data so others can recreate your problem — preferably in the form of a minimal, complete, and reproducible example https://stackoverflow.com/help/minimal-reproducible-example – Scransom Nov 11 '22 at 03:34
  • (And the R package reprex is very helpful for doing that https://reprex.tidyverse.org) – Scransom Nov 11 '22 at 03:36
  • Does this answer your question? [ggplot2: Changing the order of stacks on a bar graph](https://stackoverflow.com/questions/34716245/ggplot2-changing-the-order-of-stacks-on-a-bar-graph) – hamagust Nov 12 '22 at 00:12

0 Answers0