我有两个问题我搞不懂我们的谷歌:
Data和ggplot:
x = rnorm(n = 500, mean = 0.5, sd = 0.3)
y = rnorm(n = 500, mean = 6, sd = 1)
data = merge(x, y, by = "row.names", all = TRUE)
data %>% ggplot(aes(x, y))+
geom_density_2d_filled(contour_var = "ndensity", bins = 5)+
theme_classic()
(1)如何在所有点周围绘制轮廓?目前,20%的值具有与背景相同的颜色。应该添加新层吗?
(2)如何将背景色改为白色和渐变色以酿造"Blues“调色板(所有大于0的值应与白色背景有明显的蓝色)?
发布于 2020-07-28 18:45:46
您可能希望从geom中解耦stat,因为geom_density_2d_filled()
绘制多边形,但也将外层包含为矩形。
这是我的建议:
x = rnorm(n = 500, mean = 0.5, sd = 0.3)
y = rnorm(n = 500, mean = 6, sd = 1)
data = merge(x, y, by = "row.names", all = TRUE)
data %>% ggplot(aes(x, y))+
stat_density_2d(geom = "polygon", contour = TRUE,
aes(fill = after_stat(level)), colour = "black",
bins = 5) +
scale_fill_distiller(palette = "Blues", direction = 1) +
theme_classic()
发布于 2020-07-28 19:35:30
感谢teunbrand!但这些点仍然在等高线之外。
set.seed(2)
data %>% ggplot(aes(x, y))+
stat_density_2d(geom = "polygon", contour = TRUE,
aes(fill = after_stat(level)), colour = "black",
bins = 5)+
geom_point()+
scale_fill_distiller(palette = "Blues", direction = 1) +
theme_classic()
https://stackoverflow.com/questions/63131637
复制相似问题