如何将不同的颜色应用于点和文本,但在同一组中?
我正在尝试绘制一个剧情,其中这些点的颜色是红色,绿色,蓝色的3组和相关标签的颜色为深色,深色,深色蓝色。
我尝试了以下代码,但没有使用深色。
library(ggplot2)
ggplot(data.frame("Year" = 2013:2022,
"Value" = round(rnorm(10), 1),
"Group" = sample(letters[1:3], 10, T)),
aes(Year, Value)) +
geom_point(aes(color = Group)) +
geom_text(aes(label = Value, color = Group), vjust = -1, show.legend = FALSE) +
scale_color_manual(values = c("red", "green", "blue", "darkred", "darkgreen", "darkblue"))
I am trying to draw a plot in which the colors of the points are red, green, blue for 3 groups and colors of the associated labels are darkred, darkgreen, darkblue.
I tried the following code, but the dark colors are not used.
library(ggplot2)
ggplot(data.frame("Year" = 2013:2022,
"Value" = round(rnorm(10), 1),
"Group" = sample(letters[1:3], 10, T)),
aes(Year, Value)) +
geom_point(aes(color = Group)) +
geom_text(aes(label = Value, color = Group), vjust = -1, show.legend = FALSE) +
scale_color_manual(values = c("red", "green", "blue", "darkred", "darkgreen", "darkblue"))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找到了似乎可以做您想要的
ggnewscale
软件包。https://ggplot2.tidyverse.org/articles.org/articles/faq-customicles/faq-customising..htmis.htmlis..htmll#颜色
在2022-06-29创建的 reprex软件包(v2.0.1)
I found the
ggnewscale
package that seems to do what you want.https://ggplot2.tidyverse.org/articles/faq-customising.html#colours
Created on 2022-06-29 by the reprex package (v2.0.1)
我们可以使用
填充
而不是颜色作为点并将形状设置为21。如果您不希望要点周围的边框,请添加stroke = Na
到GEOM_POINT
。We can use
fill
instead of color for points and set the shape to 21. If you don't want the border around the points, addstroke = NA
togeom_point
.