【发布时间】:2020-06-25 20:30:21
【问题描述】:
我制作了一个山脊线图,但我想为其添加自定义标记(弹出我添加的代表)。我能想到的最好的方法是添加标签。这并不理想。
我找到了this 链接,这更符合我的要求。但我无法让该示例适用于我的案例(使用 fill = 绘制因子水平)。
下面是一些我能想到的最好的输出。
谢谢。
library(tidyverse)
library(ggridges)
dfs <-
data.frame(
"estimate" = rnorm(300),
"loading" = factor(rep(1:5, 60)),
"set" = factor(rep(1:3, 100),),
"pop" = rep(c(0.1, 0.15, 0.20, 0.05, 0.7), 60)
)
ggplot(dfs, aes(x = estimate, y = loading, fill = set)) +
geom_density_ridges(
jittered_points = TRUE,
point_shape = "|", point_size = 2, size = 0.25,
position = position_points_jitter(height = 0), alpha = 0.6, scale = 1.2)
#> Picking joint bandwidth of 0.395
loadsummary2 <- crossing("set" = dfs$set, "loading" = dfs$loading)
loadsummary2$pop <- rep(c(0.1, 0.15, 0.20, 0.05, 0.7), 3)
ggplot(dfs, aes(x = estimate, y = loading, fill = set)) +
geom_density_ridges(
jittered_points = TRUE,
point_shape = "|", point_size = 2, size = 0.25,
position = position_points_jitter(height = 0), alpha = 0.6, scale = 1.2) +
geom_label(data = loadsummary2, aes(y = loading, x = pop), label = "*")
#> Picking joint bandwidth of 0.395
由reprex package (v0.3.0) 于 2020-03-13 创建
【问题讨论】:
-
这比我所拥有的有了明显的改进。但如果可能的话,类似于我链接的解决方案会更好。
标签: r ggplot2 data-visualization ggridges ridgeline-plot