0

I have a bar plot of categorical variables. I'm trying to make the labels for the axis flush with the axis; essentially, justify the base of the bars to the labels. Any help would be appreciated.

Here's the code for the graph.

travel_deaths %>%
     filter(Type %in% commuting,
                      data_type == "Journeys") %>% #filter out the stupid air travels
     mutate(rank = rank(.$deaths)) %>%
     ggplot(aes(x = reorder(Type, rank, order = TRUE), y = deaths, fill = factor(rank))) +
     geom_bar(stat="identity", show.legend = FALSE) +
     geom_text(aes(label = deaths), nudge_y = 40) +
     ggtitle("Deaths per Billion Trips") +
     scale_fill_manual(values = bloody(9)) +
     theme(axis.text.y = element_text(hjust = 1),
           axis.ticks.y = element_blank()) +
     coord_flip()

Currently it looks like this

Currently image

This is what I am hoping to achieve

Hopeful image

David
  • 195
  • 1
  • 1
  • 10
  • 4
    Does adding `scale_y_continuous(expand = c(0,0), limits = c(0, 1700))` before you flip the coordinates give you what you're looking for? – sumshyftw May 16 '19 at 22:05
  • That did help! Can you explain what is happening in that line of code? – David May 16 '19 at 22:44
  • 1
    Duplicate of [How to remove space between axis & area-plot in ggplot2?](https://stackoverflow.com/questions/22945651/how-to-remove-space-between-axis-area-plot-in-ggplot2) – M-- May 16 '19 at 22:50
  • And duplicate of [How can I set exactly the limits for axes in ggplot2 R plots?](https://stackoverflow.com/questions/48255449/how-can-i-set-exactly-the-limits-for-axes-in-ggplot2-r-plots?noredirect=1&lq=1) – M-- May 16 '19 at 22:50

0 Answers0