我的代码运行良好,直到我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")