combine scale_y_continuous() and scale_reverse()

15 views
Skip to first unread message

Paul

unread,
Mar 25, 2015, 2:17:12 PM3/25/15
to ggp...@googlegroups.com
I'm trying to define custom breaks, and also reverse the scale.  If I run these options, they discard eachother.  How do I do this?
Sorry for the stupid example, but I gave up trying to replicate my real data

exampledata = matrix(sample.int(15, size = 30*10, replace = TRUE), nrow = 30, ncol = 10)
exampledata
= as.data.frame(exampledata)
exampledata$row
= as.numeric(row.names(exampledata))
exampledata$col
= rep(seq(1, 10), 3)
library
(reshape2)
exampledata
= melt(exampledata, id=c("row","col"))
plot
= ggplot(exampledata, aes(col, row)) + geom_tile(aes(fill = value), colour = "white")
plot
= plot + scale_fill_gradient(low="white", high="steelblue")


# I want every row displayed..
plot
= plot + scale_y_continuous(breaks = c(seq(1:30)))
plot
# but I want to reverse the y axis
plot
= plot + scale_y_reverse()
plot




Brandon Hurr

unread,
Mar 25, 2015, 2:22:31 PM3/25/15
to Paul, ggplot2
Does this do what you want? 

plot + scale_y_reverse(breaks = c(seq(1:30)))


On Wed, Mar 25, 2015 at 11:17 AM, Paul <pault...@gmail.com> wrote:
breaks = c(seq(1:30)


Paul Tanger

unread,
Mar 25, 2015, 2:29:03 PM3/25/15
to Brandon Hurr, ggplot2
Perfect, thank you!  I didn't know this was possible to specify additional arguments to scale_y_reverse()
Reply all
Reply to author
Forward
0 new messages