我想缩小geom_tile的高度和宽度。
我意识到我的问题类似于 How to adjust the tile height in geom tile?,但我的y值是字符串而不是坐标,所以我不确定如何根据高度调整y值。
我将高度和宽度缩小0.5,但它会产生"灰色空间"瓷砖之间。有没有办法删除"灰色空格"瓦片彼此相邻?
# data frame
fd=data.frame(x = rep(c("x","y","z"),3),
y=c("a","b","c","b","c","a","c","a","b"),
z=c(0,1,0,1,1,1,0,0,1))
# plot
(p <- ggplot(fd, aes(x, y, height=.5, width=.5)) + geom_tile(aes(fill = z))
+ scale_fill_gradient(low = "white",high = "steelblue", limits=c(0,1))
+ theme_grey()
+ labs(x = "", y= "")
+ scale_x_discrete(expand = c(0, 0))
+ scale_y_discrete(expand = c(0, 0))
+ theme(legend.position = "none", axis.ticks = element_blank(), axis.text.x = element_text(size=12, angle=90, hjust=0, colour="black")))
答案 0 :(得分:4)
只需删除aes(..., width=.5, height=.5)
(p <- ggplot(fd, aes(x, y)) + geom_tile(aes(fill = z))
+ scale_fill_gradient(low = "white",high = "steelblue", limits=c(0,1))
+ theme_grey()
+ labs(x = "", y= "")
+ scale_x_discrete(expand = c(0,0))
+ scale_y_discrete(expand = c(0,0))
+ coord_fixed(ratio=1)
+ theme(legend.position = "none",
axis.ticks = element_blank(),
axis.text.x = element_text(size=12, angle=90, hjust=0, colour="black")))