【发布时间】:2021-02-03 17:01:17
【问题描述】:
第一次发帖,如有冒犯请见谅。
数据(russ_defensive)看起来像这样
此代码旨在创建一个由大写条件填充的堆叠条的 facet_grid,并根据行业是否具有防御性,将 axis.text.x 颜色设置为红色或黑色
library(dplyr)
library(ggplot2)
chart_foo <- ggplot(data = russ_defensive, aes(x = industry)) +
facet_grid(~ sector, space = "free", scales="free") +
geom_bar(stat="count") + aes(fill = capitalisation) +
theme(axis.text.x = element_text(angle = 90, color = ifelse(russ_defensive$defensive_industries == "N", "red", "black")))
大约一半的行业是非防御性的(因此 russ_defensive$defensive_industries 为“N”),但是此代码仅将其中一个标签变为红色(请参阅here)并给出以下错误:
Warning message:
Vectorized input to `element_text()` is not officially supported.
Results may be unexpected or may change in future versions of ggplot2.
这个/替代方法是否有一个简单的修复方法,可以根据数据集的列有条件地格式化标签?
感谢您的帮助,如果可重现的数据集有用,请告诉我。
【问题讨论】:
标签: r ggplot2 conditional-formatting facet facet-grid