Intelligently flip a plot with discrete data on the X axis.

acid_coord_flip(object)

Arguments

object ggplot.

Value

ggplot.

Details

This function puts the samples that were near the left origin on the X at the top on the Y axis, making them more human readable.

Note

To my knowledge, there's not an easy way to create a ggproto object (via CoordFlip ggproto call internally) that lets you reorder the samples on the Y-axis to be reversed. So this function works directly on the ggplot object instead of a ggproto, and therefore doesn't currently support the + operator.

Updated 2020-03-11.

• coord_flip().

• ggplot2::ggproto().

• ggplot2:::add_ggplot.

• ggplot2:::+.gg.

• https://stackoverflow.com/questions/40450904

• https://stackoverflow.com/questions/34227967

• https://cran.r-project.org/web/packages/ggplot2/vignettes/ extending-ggplot2.html

• https://github.com/tidyverse/ggplot2/blob/master/R/ggproto.r

Examples

library(ggplot2)
g <- ggplot(data = mpg, aes(x = class)) + geom_bar()

## Notice the difference in Y axis sample order.
g + coord_flip()
g %>% acid_coord_flip()