r - 删除图例中的行
问题描述
如何删除与图例上的蓝点相交的线?我能够通过使用从项目 1 和 2 中删除点
guides(color = guide_legend(override.aes = list(shape = c(NA,NA,16))))
但不能从第三项中删除该行。预先感谢。
下面是我正在使用的代码......
library(ggplot2)
library(scales)
white.st2 <- structure(list(Year = c(1992, 1993, 1994, 1995, 1996, 1997, 1998,
1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
), ws_est_abundance = c(NA, 18257, 144672, NA, NA, 143795, 98717,
NA, NA, 57641, 32283, NA, NA, 55180, 124844, 175981, 100915,
90702), perc_ws_pop = c(NA, 3.789, 4.418, NA, NA, 8.129, 9.088,
NA, NA, 8.898, 8.595, NA, NA, 5.252, 5.599, 6, 6.2, 6.899), est_ws_abundance = c(NA,
692, 6392, NA, NA, 11689, 8971, NA, NA, 5129, 2775, NA, NA, 2898,
6991, 10559, 6257, 6258)), row.names = c(NA, -18L), class = "data.frame")
ggplot(white.st2,aes(Year,est_ws_abundance)) + geom_point(aes(color="Estimated abundance\n of 15-year
old white sturgeon"),size=3) + labs(x="", y="Number of 15-Year Old\n White Sturgeon",title='Estimated
Abundance of 15-Year old White Sturgeon\n In San Pablo and Suisun Bays, 1992-2009') + theme_bw() +
geom_hline(aes(yintercept=5500,color='1967-1991 average')) +
geom_hline(aes(yintercept=11000,color='AFRP production target'),size=0.7) +
theme(legend.position='bottom',
legend.direction = "horizontal",legend.title = element_blank()) +
scale_y_continuous(labels=comma,breaks=seq(0,13000,1000)) + scale_x_continuous(breaks=seq(1992,
2009, 1)) + guides(color = guide_legend(override.aes = list(shape = c(NA,NA,16)))) +
scale_colour_manual("", breaks = c("1967-1991 average", "AFRP production target","Estimated
abundance\n of 15-year old white sturgeon"),values = c("green", "red","blue"))
解决方案
基于这个答案,您也可以覆盖线型。
所以添加linetype=c(1,1,NA)
到override.aes
列表中。换句话说,改变你的:
guides(color = guide_legend(override.aes = list(shape = c(NA,NA,16))))
至:
guides(color = guide_legend(override.aes = list(shape = c(NA,NA,16), linetype=c(1,1,NA))))
推荐阅读
- c++ - 最快的素数测试(可以是概率的)
- java - 流分组按枚举类型列表
- c# - 在 WCF C# 应用程序中模拟并发或多线程
- google-apps-script - 谷歌表格想要删除所有行接受保留列表中的行
- r - 使用 R 中的 head 和 tail 函数只显示行名?
- javascript - 在动画中重复内容阅读更多/更少
- javascript - 在 Typescript 中使用 Ant Design 的轮播下一个和上一个窗格方法?
- javascript - GraphQL query structure
- delphi - GDI+ drawing on a TBitmap
- ios - Displaying Push Notification Badges Without Notification Service Extension