匹配 R 图中图例中的颜色
我刚刚开始使用 R,我正在尝试制作一个散点图,该图根据不同的属性具有不同的颜色。例如:
data.a = 1:5
data.b = 1:5
data.c = c("yes", "no", "yes", "maybe", "no")
plot(data.a, data.b)
我想要一个图例,对于 data.c 的“是”、“否”和“可能”点,它具有不同的颜色。我还希望点成为图例中的颜色。
I'm just starting to use R and I'm trying to make a scatter plot which has different colors based on different attributes. For example:
data.a = 1:5
data.b = 1:5
data.c = c("yes", "no", "yes", "maybe", "no")
plot(data.a, data.b)
I want to have a legend which is different colors for points which are "yes", "no", and "maybe" for data.c. I would also like points to be the colors in the legend.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
详细说明@MYaseen208的答案:对于图例(给出他的代码),你想要类似的东西:
To elaborate on @MYaseen208's answer: for the legend (given his code) you want something like:
对于 ggplot2 来说,这似乎是一个很好的案例:
This seems like a good case for ggplot2:
试试这个
Try this one