【发布时间】:2020-02-10 10:14:33
【问题描述】:
我有一个数据框,我想创建一个带有主轴和次轴的条形图。
geom_bar(data=top_ten_S, aes(x=Combination, y=AvgTopline), stat="identity",fill="red") +
coord_flip() +
geom_text(
data=top_ten_S,
aes(
x=Combination, y=AvgTopline,
label=paste0("R",round(AvgTopline,0)),
hjust=ifelse(AvgTopline < max(top_ten_S$AvgTopline) / 1.5, -0.1, 1.1), # <- Here lies the magic
),
)
我的 df 看起来像
top_ten_S <- data.frame(Combination = c("a", "b", "c"),
Nrcustomers = c(20, 200, 1900),
AvgTopline = c(1000,3000,1500))
我只能用上面的代码绘制一列 - 我想要一个辅助轴,以便我可以针对 NrCustomers 和 AvgTopline 绘制组合
【问题讨论】:
-
不确定它是否与您正在尝试做的事情有关,但这里有一个previous so question regarding two different y-axis with an answer from Hadley Wickham
-
它是但不是直接的,因为我有不同比例的数值。谢谢推荐。