我试图为每组绘制2种不同颜色的2条实线,但也在这些线条周围添加相同颜色的虚线,然后添加图例.出于某种原因,我在使用"虚线"或"虚线"时遇到了麻烦,似乎我正在两次绘制虚线.我也没有得到正确的传说,我得到了错误Adding another scale for 'colour', which will replace the existing scale.
你能帮我弄清楚我做错了什么吗?这是一个示例数据集和我尝试过的内容:
x <- c(10, 20, 50, 10, 20, 50)
mean = c(52.4, 98.2, 97.9, 74.1, 98.1, 97.6)
group = c(1, 1, 1, 2,2,2)
upper = c(13.64, 89, 86.4, 13.64, 89, 86.4)
lower = c(95.4, 99.8, 99.7, 95.4, 99.8, 99.7)
data <- data.frame(x=x,y=mean, group, upper, lower)
ggplot(data, aes(x = x, y= mean, group = as.factor(data$group), colour=as.factor(data$group))) + geom_line() + geom_point() + geom_line(data=data,aes(x=x, y=lower, group = as.factor(data$group), colour=as.factor(data$group), linetype="dotted")) …Run Code Online (Sandbox Code Playgroud)