我以前没有用过这种方式提问,如果我没有提供所需内容或没有足够详细的解释,请原谅。我正在使用
在
如果不行,我能否重叠一个带有较小线宽和不同颜色的第二个
以下是示例代码。
ggplot2
中的geom_step
尝试为具有两个单独的二级因子(编码为单个四级因子)的数据生成阶梯曲线。我希望以下第一个因子(在下面是A vs B)由颜色表示,第二个因子(在下面是1 vs 2)由线条填充表示,即填充与白色。这是我正在寻找的东西的修改后仿制品:
![enter image description here](https://istack.dev59.com/yJJQ9.webp)
ggplot2
中的geom_step
构建的线条上添加边框是否可能?如果不行,我能否重叠一个带有较小线宽和不同颜色的第二个
geom_step
线,以“手动”添加线条填充?我已经尝试在scale_colour_manual
项中添加具有不同颜色的另一个geom_step
,但这只是复制了第一个geom_step
曲线并返回消息“ 'colour'的比例已经存在。添加另一个比例尺'colour',将替换现有比例尺。”以下是示例代码。
events <- rep(c(0,1,2,3,4),4)
individual <- (as.factor(rep(c("A1","A2","B1","B2"),each=5)))
step <- c(1,2,3,4,5,3,4,5,6,7,5,6,7,8,9,7,8,9,10,11)
df <- data.frame(events,individual,step)
ggplot(df, aes(x=events, group=individual, colour=individual, y=step)) +
geom_step(size=1.8) +
scale_colour_manual(values=c("green2","green2", "orange", "orange"), name="Individual")
g
,那么使用g + geom_step(data=df[grepl("2",individual),] , col="white", size=1)
来添加一个白色条纹。[请注意在geom_step
中需要再添加一个data=
参数]. 但这不会影响图例。 - user20650