简体   繁体   中英

ggplot2 heatmap layout

consider the following heatmap:

df <- data.frame(a=rep(letters[1:10],10), b=rep(letters[1:10], each=10), c=sample(2,100, replace=TRUE))
ggplot(df, aes(a, b)) + geom_tile(aes(fill= c))

As it can be seen from the plot, between the segments of the x-axis, there are white vertical lines separating the values of the x-axis. Is it somehow possible to add such white horizontal lines to separate the segments of the y-axis like the ones can be seen on the second plot here:

http://learnr.wordpress.com/2010/01/26/ggplot2-quick-heatmap-plotting/

Also, is it possible to increase the margin of the grey background to have it as big as in the second plot of the above link?

If you're still looking for an answer:

In the comment above, white needs to be enclosed in quotes.

To increase the size of the gray border, use expand inside scale_x_...() and scale_y_...() functions. "Expand" is a two element vector: the first element is a multiplicative constant, the second element is an additive constant. The constants ensure that data points are plotted some distance away from the axes. When both are set to 0, there is no border.

library(ggplot2)
df <- data.frame(a=rep(letters[1:10],10), b=rep(letters[1:10], each=10), c=sample(2,100, replace=TRUE))

ggplot(df, aes(a, b)) + geom_tile(aes(fill = c), colour = "white") +
   scale_x_discrete(expand = c(0, 1)) + scale_y_discrete(expand = c(0, 1)) 

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM