我创建了自己的数据框,如何在 ggplot 中创建图例?
我已经创建了自己的data.frame并尝试绘制它。 但是,我只是无法让我的传奇弹出。
我认为在数据的情况下出现了问题。框架部分..但不清楚
有人可以帮我吗?
data <- data.frame(x=c(1, 2, 3, 4, 5),
y1=c(1, 3, 5, 6, 3),
y2=c(2, 4, 1, 3, 4))
data
data_plot <- ggplot(data, aes(x), col=group) + geom_smooth(aes(y=y1), color='black') + geom_smooth(aes(y=y2), color='blue') + labs(x="xxx", y="yyy", title="I need help")
data_plot
I have created my own data.frame and trying to plot it.
However, I just cant get my legend to pop up.
I think something is wrong on the case of the data.frame part.. but not clear
Could anyone please help me?
data <- data.frame(x=c(1, 2, 3, 4, 5),
y1=c(1, 3, 5, 6, 3),
y2=c(2, 4, 1, 3, 4))
data
data_plot <- ggplot(data, aes(x), col=group) + geom_smooth(aes(y=y1), color='black') + geom_smooth(aes(y=y2), color='blue') + labs(x="xxx", y="yyy", title="I need help")
data_plot
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须在
aes(...)
中指定颜色,否则它们不会在自动生成的图例中弹出:由 reprex 包 (v2.0.0)
You must specify colors inside
aes(...)
, otherwise they would not pop up in the automatically generated legend:Created on 2022-03-30 by the reprex package (v2.0.0)
您需要在
aes()
中定义color
,例如geom_smooth(aes(y=y1, color='black'))
并使用scale_color_identity ()
分配颜色。身份尺度的默认值为guide = "none"
。情节:
示例数据:
You need to define
color
inaes()
, such asgeom_smooth(aes(y=y1, color='black'))
and usescale_color_identity ()
to assign colours. The default isguide = "none"
for identity scales.Plot:
Sample data: