小编hum*_*erp的帖子

使用 ggplot2 对轴文本进行条件格式化

我正在尝试格式化轴文本以反映用于填充下图中的几何图形的相同组。颜色方案是为 aes() 中的 fill 参数选取的,导致 a 和 b、c 之间的颜色不同。然而,element_text() 中使用的 ifelse 语句不会产生正确的颜色格式。

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 …
Run Code Online (Sandbox Code Playgroud)

r ggplot2

2
推荐指数
1
解决办法
2611
查看次数

标签 统计

ggplot2 ×1

r ×1