考虑这个简单的例子
library(tidyverse)
tibble(x = as.factor(c('good', 'neutral', 'bad')),
y = as.factor(c('bad', 'neutral', 'bad'))) %>%
ggplot(aes(x = x, y = y)) + geom_point()
Run Code Online (Sandbox Code Playgroud)
我想提出的X标签(good,neutral,bad)以不同的颜色框。例如,good(在x轴和y轴上)将被一个小绿色框包围,依此类推。
我可以在里面做ggplot2吗?
像这样?
tibble(x = as.factor(c('good', 'neutral', 'bad')),
y = as.factor(c('bad', 'neutral', 'bad'))) %>%
ggplot(aes(x = x, y = y)) +
geom_point() +
theme(axis.text.x = element_text(color = c('red', 'blue', 'green')))
Run Code Online (Sandbox Code Playgroud)
您的情节:
另一种漂亮的贫民窟解决方案,使用 grid
tibble(x = as.factor(c('good', 'neutral', 'bad')),
y = as.factor(c('bad', 'neutral', 'bad'))) %>%
ggplot(aes(x = x, y = y)) +
geom_point() +
theme(axis.text.x = element_text(color = c('red', 'blue', 'green')))
Run Code Online (Sandbox Code Playgroud)