【发布时间】:2020-09-06 14:29:56
【问题描述】:
我希望将绘图的图例从垂直线旋转到水平线,但在图中保持实际线垂直。 solutions 有许多 hack 类型,但我认为现在可以使用 ggstance 包轻松完成,但我不确定如何实现。
library(tidyverse)
library(ggstance)
df <- tibble(x = rnorm(40))
df_stats <-
df %>% summarise(
mean = mean(x),
median = median(x)
) %>%
gather(key = legend, value = value, mean:median)
df %>%
ggplot(aes(x = x)) +
geom_histogram(bins = 20) +
geom_vline(data = df_stats, aes(xintercept = value, color = legend))
使用ggstance 有什么建议吗?谢谢
编辑@Allan Cameron 评论
由于 ggstance 已被最新版本的 ggplot 取代,我很高兴看到有人可能有任何解决方案?
【问题讨论】:
-
ggstance已被最新版本的 ggplot 取代,正如 here 所解释的那样,所以我认为这不是正确的使用途径。 -
感谢您的提示。看来
key_glyph下面的参数就是我所需要的! -
但是
ggstance是一个很好的指针,因为在它的文档中我发现了key_glyph参数:)