我有数据绘制为点,并想添加密度图到图表.来自ggExtra或其他包的边际图解决方案没有提供我想要的自由度,因此希望在生成ggmap的同时生成密度图.
df = data.frame(x = rnorm(50, mean = 10),
y = runif(50, min = 10, max = 20),
id = rep(LETTERS[1:5], each = 10))
ggppp = ggplot(data = df, mapping = aes(x, y, color = id)) +
geom_point() + theme_bw()
ggppp +
geom_density(mapping = aes(y = y,
col = id),
inherit.aes = FALSE, bounds = c(-Inf, Inf)) +
geom_density(mapping = aes(x = x,
col = id),
inherit.aes = FALSE, )
有没有办法将密度图移动到x或y位置的其他值(如将密度线移动到下图中箭头的尖端)?