Let's say I want to plot this made up population data.
dat <- data.frame(year_start_aby = c(-20, -10, 0, 10, -20, -10, 0, 10, -20, -10, 0, 10),
year_end_aby = c(-10, 0, 10, 20, -10, 0, 10, 20, -10, 0, 10, 20),
population = c(16000000, 19900000, 15300000, 16900000, 40000000, 55000000, 43100000, 50000000, 120000000, 125000000, 0, 0),
planet = c("Tatooine", "Tatooine", "Tatooine", "Tatooine", "Naboo", "Naboo", "Naboo", "Naboo", "Alderaan", "Alderaan", "Alderaan", "Alderaan"))
I can easily plot population on a continuous x-axis by year_start_aby like this:
ggplot(dat, aes(year_start_aby, population, color = planet)) +
geom_line() +
theme_classic()
But if I want the x-axis to be plotted as year range factors (-20 ABY -- 0 ABY, etc.) rather than continuous year values, how can I do this?
Help me, Obi-Wan Kenobi -- you're my only hope.