R 将边框添加到geom_线段中的线段

R 将边框添加到geom_线段中的线段,r,ggplot2,R,Ggplot2,我试图找出如何更改使用geom\u段的甘特图的边框颜色 以下是一些数据: df <- structure(list(start_int = c(0, 5, 0, 0, 9, 10, 12, 10, 14, 18, 22, 24, 27, 29, 26), end_int = c(5, 6, 8, 9, 10, 12, 14, 15, 15, 20, 23, 27, 30, 31, 32), ids = c("C", "C", "A", "C", "B", "B", "C", "A",

我试图找出如何更改使用
geom\u段的甘特图的边框颜色

以下是一些数据:

df <- structure(list(start_int = c(0, 5, 0, 0, 9, 10, 12, 10, 14, 18, 
22, 24, 27, 29, 26), end_int = c(5, 6, 8, 9, 10, 12, 14, 15, 
15, 20, 23, 27, 30, 31, 32), ids = c("C", "C", "A", "C", "B", 
"B", "C", "A", "B", "C", "B", "B", "B", "B", "C")), .Names = c("start_int", 
"end_int", "ids"), class = c("data.frame"), row.names = c(10L, 11L, 1L, 14L, 3L, 6L, 12L, 2L, 7L, 13L, 4L, 8L, 9L, 5L, 15L))
这就产生了:

现在,我如何在每个线段周围添加一个红色边框


geom_段
是这样做的,还是
geom_段
更合适?(由于y轴的分类,不确定是否有效)。

您可以将“较小”的线段覆盖在“较大”的线段上:

ggplot() + 
geom_segment(data=df, aes(x=start_int, xend=end_int, y=ids, yend=ids), size=11, colour="red") + 
geom_segment(data=df, aes(x=(start_int+0.1), xend=(end_int-0.1), y=ids, yend=ids), size=10) +
theme_bw()

geom_段具有色彩美感。它没有填充美学。您需要使用geom__\n rect。
ggplot() + 
geom_segment(data=df, aes(x=start_int, xend=end_int, y=ids, yend=ids), size=11, colour="red") + 
geom_segment(data=df, aes(x=(start_int+0.1), xend=(end_int-0.1), y=ids, yend=ids), size=10) +
theme_bw()