简体   繁体   English

使用ggplot2更改图例文本的颜色与上述geom_point()的颜色相同

[英]Changing colour of legend text same as mentioned colour of geom_point() using ggplot2

I have legend having three values namely - high low med. 我有三个值的传说-高低中。

在此处输入图片说明

I want the colour of text high to same as shape object ie blue and low as red and med as green Colour are mentioned in geom_point(). 我想文相同的颜色,形状对象,即蓝色和低红色和MED的绿色在geom_point提到()。

Is it possible to change the colour of legend text? 可以更改图例文本的颜色吗?

If p is your plot, you can save it as a grob and edit the labels one-by-one with grid commands, 如果p是您的绘图,则可以将其另存为grob,然后使用网格命令逐一编辑标签,

g = ggplotGrob(p)
grid.draw(g)
grid.edit("label-3", grep=TRUE, global=TRUE,
           gp=gpar(col="red", cex=1))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM