R:ggplot geom_hline自定义图例,带有scale_color_manual错误

时间:2018-06-20 19:36:49

标签: r ggplot2 geom-hline

我的代码运行良好,直到我在情节中添加了另一个geom_hline()层。现在,我不断收到此错误,而且我不明白自己在做什么错。我想在提供的yintercept上有两条水平线都为红色,但有一条点线或虚线。

Error in `[[<-.data.frame`(`*tmp*`, v, value = c(1, 2)) : 
  replacement has 2 rows, data has 1

代码:

box_whisk_graph<-ggplot(data = box_fresh_chloride, aes(x = factor(year), y = val)) +
  geom_boxplot(coef=10) +
  geom_hline(aes(yintercept = 230,color="red"),size=1.3)+
  geom_hline(aes(yintercept = 860,color="red"),size=1.3)+
scale_color_manual("",
                     values = c("red"="red","red"="red"),
                     labels=c("Freshwater Aquatic Life (chronic)\nCriteria for chloride = 230 mg/L","Freshwater Aquatic Life Criteria (acute) for chloride = 860 mg/L"),
      guide=guide_legend(override.aes=list(linetype=c(1,2), lwd=c(1,0.5))))

数据吞吐量:

structure(list(orgid = c("USGS-NJ", "USGS-NJ", "USGS-NJ", "USGS-NJ", 
"USGS-NJ", "USGS-NJ"), locid = c("USGS-01482500", "USGS-0146453250", 
"USGS-01392150", "USGS-01411035", "USGS-01411466", "USGS-01411444"
), stdate = structure(c(16394, 16610, 16328, 16583, 16602, 16602
), class = "Date"), sttime = c("09:45:00", "11:00:00", "10:40:00", 
"09:45:00", "12:00:00", "10:30:00"), charnam = c("Chloride", 
"Chloride", "Chloride", "Chloride", "Chloride", "Chloride"), 
    val = c(23.6, 221, 144, 10.8, 10.5, 5.76), valunit = c("mg/l", 
    "mg/l", "mg/l", "mg/l", "mg/l", "mg/l"), swqs = c("FW2-NT", 
    "FW2-NT", "FW2-NT", "PL", "FW2-NT", "PL"), region = c("Lower Delaware", 
    "Lower Delaware", "Northeast", "Atlantic Coast", "Lower Delaware", 
    "Atlantic Coast"), WMA = c(17L, 20L, 4L, 15L, 17L, 16L), 
    year = c(2014, 2015, 2014, 2015, 2015, 2015)), .Names = c("orgid", 
"locid", "stdate", "sttime", "charnam", "val", "valunit", "swqs", 
"region", "WMA", "year"), row.names = c(NA, 6L), class = "data.frame")

0 个答案:

没有答案