8

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)) 
1
  • 4
    ggplot(data, aes(x, forcats::fct_rev(y))) + geom_tile(aes(fill=prob)) Commented Nov 21, 2016 at 21:07

1 Answer 1

10

I figured this out.

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

geom_tile

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.