When I use geom_tile()
with ggplot2
and discrete scales the labels are in ascending order on the x-axis and in descending order on the y-axis:
#some sample data
a <- runif(400)
a <- matrix(a, ncol=20)
colnames(a) <- letters[seq( from = 1, to = 20 )]
rownames(a) <- letters[seq( from = 1, to = 20 )]
a <- melt(a)
When I plot the dataframe a
this comes out:
ggplot(a, aes(X1, X2, fill = value)) + geom_tile() +
scale_fill_gradient(low = "white", high = "black", breaks=seq(from=0, to=1, by=.1), name="value") +
opts(axis.text.x=theme_text(angle=-90, hjust=0)) +
scale_x_discrete(name="") + scale_y_discrete(name="")
and the coords are labeled differently for x and y:
I would like to have the labels sorted from a-z from top to bottom and from left to right. is there a quick way to do this?
limits = c(0, 1)
to your currentscale_colour_gradient
command - currently 1 is outside the limits of the scale and isn't coloured correctly in the legend. – hadley