提问人:Alice Yan 提问时间:11/14/2023 最后编辑:Alice Yan 更新时间:11/14/2023 访问量:52
如何将正方形放置在网格框内而不是它的交叉处?[复制]
How to place the square inside of the grid box not at the crossing of it? [duplicate]
问:
ggplot(HLA, aes(x = ID, y = Description, fill = BETA)) +
geom_tile(width = 1, height = 1) + # Set the width and height of the squares to 1
scale_fill_gradient2(low = "blue", mid = "white", high = "red",
midpoint = 0, # Set the midpoint of the color scale as 0
limits = c(-4, 2), # Set the limits of the color scale as -4 and 2
guide = "colorbar", # Use a color bar as the legend
breaks = c(-4, -3, -2, -1, 0, 1, 2,3, 4)) + # Set the breaks for the legend
labs(title = "Assocation Result", x = "HLA variant", y = "Phenotype", fill = "BETA") +
theme_minimal() +# Use a minimal theme for the plot
theme(axis.text.x = element_text(angle = 30, hjust = 1)) + # Rotate the x labels 45 degrees
theme(panel.grid.major = element_line(color = "white", size = 0.5), # Set the color and size of the major grid lines
panel.grid.minor = element_blank(), # Remove the minor grid lines
panel.background = element_rect(fill = "grey95", colour = NA)) # Set the background color of the plot
正方形位于网格之外,我希望它们在盒子内。如何调整 R 代码?x 和 y 都是分类变量。
答:
0赞
PGSA
11/14/2023
#1
网格线有助于将图块与标签对齐 - 因此,您想要的是一个勾勒出每个可能图块的网格?
尝试使用内置数据集:
data("HairEyeColor")
ggplot(as.data.frame(HairEyeColor), aes(x = Hair, y = Eye, fill = Freq)) +
geom_tile(width = 1, height = 1, colour = "grey6") +
scale_fill_gradient2(low = "blue", mid = "white", high = "red",
midpoint = 30,
limits = c(0, 70),
guide = "colorbar") +
theme_minimal()
下一个:在密度图中留空
评论
grid.panel.major
grid.panel.minor
scale_y_continuous(breaks = ...)
theme_minimal()
colour = "black"
geom_tile()