R 更改频率多边形的图例标签

R 更改频率多边形的图例标签,r,ggplot2,R,Ggplot2,我在更改频率多边形上的标签时遇到问题 当我在柱状图上这样做时,它如下所示: ggplot(data=df, aes(value, fill=df$variable))+ geom_histogram(binwidth = 10, position=position_dodge(width=7), col="black") + labs(title="Exam Scores", x="Exam Score", y="Fr

我在更改频率多边形上的标签时遇到问题

当我在柱状图上这样做时,它如下所示:

ggplot(data=df, aes(value, fill=df$variable))+
  geom_histogram(binwidth = 10, position=position_dodge(width=7), col="black") +
  labs(title="Exam Scores", x="Exam Score", y="Frequency") +
  scale_fill_discrete(name="Exam", labels = c("Exam 1", "Exam 2"))
它产生这个输出:

这同样适用于箱线图

ggplot(data=df, aes(value, fill=variable)) +
  geom_boxplot(col="black")+labs(title="Exam Scores", x="Exam Score") +
  scale_fill_discrete(name="Exam", labels = c("Exam 1", "Exam 2")) +
  coord_flip()

但是,在创建频率多边形时,图例标签不会更改

ggplot(data=df, aes(value, fill=variable, color=variable)) +
  geom_freqpoly(binwidth=10) +
  labs(title="Exam Scores", x="Exam Score", y="Frequency") +
  scale_fill_discrete(name="Exam", labels = c("Exam 1", "Exam 2"))


有人知道为什么会发生这种情况吗?

。。。尝试使用
scale\u color\u discrete
而不是
scale\u fill\u discrete
geom_freqpoly
没有填充aes。谢谢,这样做有效!你能不能把它作为一个答案贴出来,这样我就可以给你适当的互联网点数:)一切都很好。总是很乐意帮忙。最佳S。