本文介绍了geom_text R中的两种颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 ggplot
,其中包含 geom_text()
:
I have a ggplot
with a geom_text()
:
geom_text(y = 4, aes(label = text))
变量文本格式如下:
number1-number2
我想知道是否可以为number1定义一种颜色,为number2定义另一种颜色(例如:红色和绿色)
I want to know if it is possible to define a color for the number1 and another color for number2 (example: red and green color)
谢谢!
Thanks!
推荐答案
一种方法是,如果您有例如标签文本(数据,aes(x,y))+ geom_text(数据,aes(x,y))+ geom_text(数据框中的数字1和数字2作为单独的列在数据框中):
One way is if you have for example the label texts of number1 and number2 as separate columns in the data frame:
ggplot(data, aes(x,y)) + geom_text(label=data[,3], color="red", vjust=0) + geom_text(label=data[,4], color="blue", vjust=1)
这篇关于geom_text R中的两种颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!