我试图在绘图中绘制两个图层 - 条形图和文本图层。条形图和文本图层由data.frame
的互斥切片构成。切片由下面的分类变量Category
的值定义。
现在,对于文本图层,我不希望显示指南。为了达到这个目的我:
droplevels
确保Difference
和geom_bar
)
show_guide = FALSE
geom_text
醇>
但是,我仍然得到省略级别的省略级别的指南。
这是一个演示问题的MWE:
dfX = data_frame(
id = rep.int(1:10, 3),
Category = factor(rep(c("All", "Other", "Difference"), each = 10)),
Value = c(rpois(20, 10), abs(runif(10))*100))
ggplot(data = droplevels(subset(dfX, !Category %in% "Difference")),
aes(x = as.factor(id), y = Value, fill = Category)) +
geom_bar(stat = "identity", position = "dodge") +
geom_text(data = droplevels(subset(dfX, Category %in% "Difference")),
aes(y = 10, label = signif(Value, 0)),
show_guide = FALSE) +
theme_bw() +
theme(legend.position = "bottom")
我不希望图例中突出显示的级别 - 我该如何实现?
答案 0 :(得分:2)
您可以取消映射fill
美学:
ggplot(data = droplevels(subset(dfX, !Category %in% "Difference")),
aes(x = as.factor(id), y = Value, fill = Category)) +
geom_bar(stat = "identity", position = "dodge") +
geom_text(data = droplevels(subset(dfX, Category %in% "Difference")),
aes(y = 10, label = signif(Value, 0),fill = NULL),
show_guide = FALSE) +
theme_bw() +
theme(legend.position = "bottom")