Examples for 'ggplot2::coord_flip'


Cartesian coordinates with x and y flipped

Aliases: coord_flip

Keywords:

### ** Examples

# Very useful for creating boxplots, and other interval
# geoms in the horizontal instead of vertical position.

ggplot(diamonds, aes(cut, price)) +
  geom_boxplot() +
  coord_flip()
plot of chunk example-ggplot2-coord_flip-1
h <- ggplot(diamonds, aes(carat)) +
  geom_histogram()
h
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
plot of chunk example-ggplot2-coord_flip-1
h + coord_flip()
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
plot of chunk example-ggplot2-coord_flip-1
h + coord_flip() + scale_x_reverse()
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
plot of chunk example-ggplot2-coord_flip-1
# You can also use it to flip line and area plots:
df <- data.frame(x = 1:5, y = (1:5) ^ 2)
ggplot(df, aes(x, y)) +
  geom_area()
plot of chunk example-ggplot2-coord_flip-1
last_plot() + coord_flip()
plot of chunk example-ggplot2-coord_flip-1

[Package ggplot2 version 3.3.6 Index]