【发布时间】:2018-06-15 06:35:22
【问题描述】:
我无法在绘图的 x 轴上以离散(因子)水平绘制垂直线。在这个解决方案中,它似乎可以工作drawing vertical line with factor levels in ggplot2
但这不适用于geom_tile?
基本上,要删除 geom_tile 中的空白,我需要将 numeric x 值转换为因子级别。但同时我想画一个带有数值的geom_vline。
这是什么问题
df <- data.frame(
x = rep(c(2, 5, 7, 9, 12), 2),
y = rep(c(1, 2), each = 5),
z = factor(rep(1:5, each = 2)))
library(ggplot2)
ggplot(df, aes(x, y)) +
geom_tile(aes(fill = z), colour = "grey50")+
geom_vline(aes(xintercept=6),linetype="dashed",colour="red",size=1)
要删除geom_tile 中的空格,需要将x 转换为factor(x)
但是当我这样做时 geom_vline 消失了!
【问题讨论】: