【发布时间】:2019-08-26 02:28:17
【问题描述】:
我正在尝试格式化轴文本以反映所使用的相同组 填充下图中的几何图形。为填充参数选择配色方案 在 aes() 中,导致 a 和 b、c 之间的颜色不同。中使用的 ifelse 语句 但是 element_text() 不会产生正确的颜色格式。
library(ggplot2)
# Make some data (emulating melted format)
df <- cbind.data.frame(c('a', 'a', 'a', 'b', 'c'),
c(5, 5, 5, 15, 45),
c(1, 1, 1, 0, 0))
names(df) <- c('variable', 'value', 'col')
# Conditional statement to be used in plot
con <- ifelse(df$col == 1, 'red', 'green')
# Call to the plot included below
ggplot(df, aes(x = variable, y = value)) +
geom_bar(stat = "identity", aes(fill = col)) +
theme(axis.text.x = element_text(angle = 45, hjust = 1, colour = con))
【问题讨论】: