My data looks like this:
d <- data.frame(X=c('x1','x2','x3','x1','x2','x3','x1','x2','x3'),
Y=c('y1','y1','y1','y2','y2','y2','y3','y3','y3'),
Value=c(1,2,1,3,1,4,3,5,2))
I use the following code to generate a heat map:
ggplot(d,aes(x=X,y=Y,fill=Value)) +
geom_tile() +
scale_fill_gradient2(low='green',mid='white',high='red',midpoint=3) +
theme(axis.text.x = element_text(angle = 90),
axis.text = element_text(size = 10),
panel.background = element_blank()) +
labs(x='',y='')
The graph is:
But, my whole data is around 500*500, so too many ticks on x axis and y axis so that the labels are impossible to recognize clearly. But I have to keep all the values.
So I want to use double x axis and double y axis. For example, the bottom x axis only keeps the lables x1, x3, x5... and the top x axis only keeps the labels x2, x4, x6.... Then I do the same to y axis. Then, the graph looks like:
I know scale_x_continuous and sec.axis might do this. But my x and y are discrete.
Could anyone help me so that the graph looks like the second one?


