如何控制geom_text中字母的颜色?
How to control color of letters in geom_text?
我想打印一行字母,每个字母用不同的颜色来标识字母的颜色和字母形状,例如:
如何使用 R 中的 ggplot 包执行此操作?
我希望能够执行以下操作:
library(ggplot2)
s <- sample(x = c("g", "c", "t", "a"), size = 100, replace = TRUE)
ggplot() + geom_text(aes(seq(s), 1, color = s), label = s)
但是我得到了错误
Error: Incompatible lengths for set aesthetics: label
有办法吗?
通过尝试、错误、一些搜索,我意识到标签可以用作美学:
s <- s[1:20] ## make shorter for example
ggplot() + geom_text(aes(seq(s), 1, color = s, label = s))
这是一件名为 'Star Wars DNA' (source)
的艺术品
我想打印一行字母,每个字母用不同的颜色来标识字母的颜色和字母形状,例如:
如何使用 R 中的 ggplot 包执行此操作?
我希望能够执行以下操作:
library(ggplot2)
s <- sample(x = c("g", "c", "t", "a"), size = 100, replace = TRUE)
ggplot() + geom_text(aes(seq(s), 1, color = s), label = s)
但是我得到了错误
Error: Incompatible lengths for set aesthetics: label
有办法吗?
通过尝试、错误、一些搜索,我意识到标签可以用作美学:
s <- s[1:20] ## make shorter for example
ggplot() + geom_text(aes(seq(s), 1, color = s, label = s))
这是一件名为 'Star Wars DNA' (source)
的艺术品