R show.legend=FALSE无法隐藏所选几何图形,当前解决方案不起作用

R show.legend=FALSE无法隐藏所选几何图形,当前解决方案不起作用,r,ggplot2,legend,R,Ggplot2,Legend,我想删除geom_路径的图例,并保留geom_点的图例。在其他人(,)之后,我尝试了下面的方法,但没有效果。任何帮助都将不胜感激 我的尝试 库(ggplot2) p您有两个geom_路径;你应该有一个 库(ggplot2) P library(ggplot2) p<-ggplot(pathDF ,aes(x=Age,y=Val,linetype=as.factor(variable))) + geom_path(aes())+ geom_path(show.legend

我想删除geom_路径的图例,并保留geom_点的图例。在其他人(,)之后,我尝试了下面的方法,但没有效果。任何帮助都将不胜感激

我的尝试
库(ggplot2)

p您有两个
geom_路径
;你应该有一个

库(ggplot2)
P
library(ggplot2)    
p<-ggplot(pathDF ,aes(x=Age,y=Val,linetype=as.factor(variable))) + 
  geom_path(aes())+
  geom_path(show.legend = FALSE)+
  geom_point(data=pointsDF ,aes(x=Age,y=Income,colour=as.factor(Person)) 
             )+  
theme(legend.position = "right", legend.title = element_blank())
p
pathDF<-structure(list(X = c(19L, 108L, 197L, 20L, 109L, 198L, 21L, 110L, 
199L, 22L, 111L, 200L, 23L, 112L, 201L), Age = c(3.5, 3.5, 3.5, 
3.75, 3.75, 3.75, 4, 4, 4, 4.25, 4.25, 4.25, 4.5, 4.5, 4.5), 
    Age.1 = c(10.5, 10.5, 10.5, 11.25, 11.25, 11.25, 12, 12, 
    12, 12.75, 12.75, 12.75, 13.5, 13.5, 13.5), Var = structure(c(1L, 
    2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L), .Label = c("lower", 
    "median", "upper"), class = "factor"), Val = c(1.019776106, 
    1.080410605, 1.280680119, 1.019818423, 1.080376888, 1.28061562, 
    1.019850565, 1.080306376, 1.281109608, 1.019855427, 1.080300184, 
    1.281871082, 1.01988598, 1.080221459, 1.282087808)), class = "data.frame", row.names = c(NA, 
-15L))

pointsDF<-structure(list(X = 1:3, Person = structure(c(1L, 2L, 2L), .Label = c("F", 
"H"), class = "factor"), Age = c(10.5, 13.5, 13.5), Income = c(0.126696833, 
0, 0), Low = c(1.076305681, 1, 1), Up = c(1.224466569, 1.114847578, 
1.192670137), Var = c(0L, 0L, 0L), Val = c(0L, 0L, 0L)), class = "data.frame", row.names = c(NA, 
-3L))