[英]R ggplot2: changing the legend title and labels in this example dataset
[英]Changing legend title and labels in R?
我是 R 的新手,最近才开始学习。
我生成了一个图,显示了两条单独的数据行,这些数据在此处链接:
我当前的图形代码是:
ggplot(Stats, aes(x=Well))+
geom_line(aes(y=Historic.Mean, colour="red", group="red"))+
geom_line(aes(y=Recent.Mean, colour="blue", group="blue"))+
labs(x="Well", y="Water Level (m)", title="Historic vs Recent Well Levels")+
scale_fill_discrete(name= "Means", labels= c("Historic", "Recent"))+
theme(axis.text.x=element_text(angle=90))
运行此代码,生成了先前显示的图,但由于某种原因未适当更新图例标题和标签。
我也试过在实验室部分包含 fill="legend title" 而不是 "scale_fill_discrete" ,但它不起作用。
有什么帮助吗?
您在实际使用colour
时不小心选择了fill
。 因此,该fill
元素提供了标签,但由于这些元素不存在,因此似乎什么也没有发生。 更改scale_fill_discrete
到scale_colour_discrete
。
如果没有 reprex,很难看出你哪里出错了,请看这里: https ://reprex.tidyverse.org/。 在此处发布通常是最佳实践,以便人们可以将您的代码粘贴在他们的 R 中并找出导致问题的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.