r - show.legend = FALSE 无法隐藏选定的 geom_ 并且当前的解决方案不起作用
问题描述
我想删除 geom_path 的图例并保留 geom_points 的图例。跟随其他人(1、2、3)我尝试了以下方法,但无济于事。任何帮助将不胜感激。
我的尝试
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))
解决方案
推荐阅读
- android - 部分设备无法读取 NfcA 卡
- ios - Swift - 更改 iPhone 背景
- python - 如何将环境变量传递给我的烧瓶应用程序
- ios - 如何从超级视图中获取所有元素(如:UiLabel,UITextfield)并设置标签文本颜色和文本字段占位符颜色
- excel - 为什么列表框不显示 Excel VBA 用户窗体中的最新条目?
- react-native - Redux React-Native:更新状态后未定义的对象
- c++ - "int* p=+s;" 是什么意思?做?
- jquery - 获取对预检请求的响应未通过访问控制检查错误 - Spring Security +Oauth2 Rest Api
- java - 使用流收集到 Map
- azure-logic-apps - 如何在 Azure 逻辑应用程序中将变量设置为“null”?