Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I reverse the Y axis in ggplot's geom_tile?

Tags:

r

ggplot2

Below is a graph. How do I reverse the Y axis , so it reads down "a b" instead of "b a", while leaving the X axis alone?

geom_tile

Code:

library(ggplot2)
levels = ordered(c('a', 'b'))
data = data.frame(x=ordered(c('a', 'a', 'b', 'b'), levels=levels),
                  y=ordered(c('a', 'b', 'a', 'b'), levels=levels),
                  prob=c(0.3, 0.7, 0.4, 0.6))
ggplot(data, aes(x, y)) + geom_tile(aes(fill=prob))
like image 581
dfrankow Avatar asked Feb 06 '23 16:02

dfrankow


1 Answers

I figured this out.

ggplot(data, aes(x, ordered(y, levels=rev(levels)))) + 
  geom_tile(aes(fill=prob))

geom_tile

like image 68
dfrankow Avatar answered Feb 08 '23 15:02

dfrankow