Simple question that I can't seem to find an answer for. Im trying to rotate a geom_raster plot from ggplot in R. Here's an example of what I mean:
Firstly, Im creating a matrix like so:
set.seed(1701)
a <- sample(1:10,100, replace=TRUE)
s <- matrix(a, nrow = 5, ncol=5)
s[upper.tri(s)] = t(s)[upper.tri(s)]
colnames(s)<- paste0("x", 1:5)
rownames(s)<- paste0("x", 1:5)
diag(s) <- 0
s
Which produces this matrix, where the diagonals = 0 start from the top left:
x1 x2 x3 x4 x5
x1 0 8 1 6 10
x2 8 0 7 1 7
x3 1 7 0 3 8
x4 6 1 3 0 9
x5 10 7 8 9 0
But when I plot it using:
ggplot(melt(s), aes(Var1,Var2, fill=value)) + geom_raster()
How do I flip the the plot so the diagonals match the numerical matrix above? I have tried coord_flip() and scale_x_discrete(position = "top") but neither solve the problem.
Any suggestions? Thanks