我想在 hline 图中添加一个图例。
我的子集的头部看起来像这样
Site Date Al
1 Bo6 2014-10-07 152.1
2 Bo1 2014-10-07 157.3
3 Bo3 2014-10-07 207.1
4 Bo4 2014-10-07 184.3
5 Bo5 2014-10-07 23.2
13 Bo6 2014-10-14 96.8
我的代码如下:
require(ggplot2)
require(reshape2)
require(magrittr)
require(dplyr)
require(tidyr)
setwd("~/Documents/Results")
mydata <- read.csv("Metals sheet Rwosnb5.csv")
mydata <- read.csv("Metals sheet Rwosnb5.csv")
L <- subset(mydata, Site =="Bo1"| Site == "Bo2"| Site == "Bo3"| Site == "Bo4"| Site == "Bo5" | Site == "Bo6", select = c(Site,Date,Al))
L$Date <- as.Date(L$Date, "%d/%m/%Y")
I <- ggplot(data=L, aes(x=Date, y=Al, colour=Site)) +
geom_point() +
labs(title = "Total Al in the Barlwyd and Bowydd in Pant-yr-afon sites B4-B9
2014-2015.", x = "Month 2014/2015",
y = "Total concentration (mg/L)") +
scale_y_continuous(limits = c(0, 500)) +
scale_x_date(date_breaks = "1 month", date_labels = "%m")
I + geom_hline(aes(yintercept= 10), linetype = 2, colour= 'red', show.legend =TRUE) +
geom_hline(aes(yintercept= 75.5), linetype = 2, colour= 'blue', show.legend = TRUE)
由于某种原因,图例不起作用——图例中有六个站点,它们之间有一条线。理想情况下,我想要一个标题 = 限制和标签 1 (10) = NRW 限制和标签 2 (75.5)= 地球化学图集限制的图例。