我的目标是在条形图的末尾构建一个带有箭头的条形图。我去geom_segment与arrow定义。我想将一列映射到透明度上,但 alpha 美学似乎不适用于箭头对象。这是代码片段:
tibble(y = c(10, 20, 30), n = c(300, 100, 200), transparency = c(10, 2, 4)) %>%
ggplot() + geom_segment(aes(x = 0, xend = n, y = y, yend = y, alpha = transparency),
colour = 'red', size = 10, arrow = arrow(length = unit(1.5, 'cm'), type = 'closed')) +
scale_y_continuous(limits = c(5, 35))
Run Code Online (Sandbox Code Playgroud)
可以很容易地观察到arrow对象在 的值较低时看起来不太好alpha,显示其骨架而不是简单、透明的形状。有什么办法可以预防吗?