调整ggplot2几何图块的高度和宽度 [英] adjust ggplot2 geom tile height and width
问题描述
我想缩小我的geom_tile的高度和宽度。
我意识到我的问题类似于 我把高度和宽度缩小了0.5,但是它在瓷砖之间产生了灰色空间。有什么方法可以去除灰色空间,以便瓷砖相邻? 只要删除 I wanted to shrink the height and width of my geom_tile. I realized my question is similar to
How to adjust the tile height in geom tile?, but my y values are strings instead of coordinates so I am not sure how to adjust my y values based on height. I shrink height and width by 0.5 but it creates "grey spaces" between the tiles. Is there any way to remove the "grey spaces" so that the tiles are adjacent to each other? Just remove the 这篇关于调整ggplot2几何图块的高度和宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
,但我的y值是字符串,而不是坐标,所以我不知道如何调整我的y值根据高度。
#数据框
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))
$ b $#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,color =black)))
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,color =black)))
# 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")))
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")))