Kuo-Hsien Chang
Kuo-Hsien Chang

Reputation: 935

ggplot2: error message occurred when using scale_y_reverse() and scale_y_continuous() together

I got an error message when I applied scale_y_reverse() and scale_y_continuous() together.

Scale for 'y' is already present. Adding another scale for 'y', which will replace the existing scale.

Here is my code:

library(ggplot2)
library(reshape2)

m <- matrix(runif(10000, 1, 100), nrow=10)
     ggplot(melt(m), aes(x=Var2, y=Var1, fill=value)) + 
     geom_tile() + coord_fixed(ratio=100) + scale_y_reverse()+
     scale_x_continuous(expand = c(0, 0)) + 
     scale_y_continuous(expand = c(0, 0))

How can I reverse the y-axis and also remove the whtie padding?

Thanks a lot.

Upvotes: 1

Views: 690

Answers (1)

Sandy Muspratt
Sandy Muspratt

Reputation: 32859

Try this (that is, use only one scale y):

 ggplot(melt(m), aes(x=Var2, y=Var1, fill=value)) + 
 geom_tile() + coord_fixed(ratio=100) + 
 scale_y_reverse(expand = c(0, 0))+
 scale_x_continuous(expand = c(0, 0))

Upvotes: 1

Related Questions