install.packages("ggpointdensity")
library(ggplot2) # Create Elegant Data Visualisations Using the Grammar of Graphics
library(ggpointdensity) # A Cross Between a 2D Density Plot and a Scatter Plot
library(viridis) # Colorblind-Friendly Color Maps for R
x= rnorm(1000000)
y= rnorm(1000000)
data = data.frame(x, y)
plot(data)
ggplot(data, aes(x, y))+
geom_point()
ggplot(data, aes(x, y)) +
geom_pointdensity() +
theme_bw()+
theme(panel.grid = element_blank(),
legend.position = c(0.15,0.75),
axis.text = element_text(size = 10))+
labs(x=NULL, y=NULL)+
scale_color_viridis(option = "turbo")->p1
p1
density.png
参考资料:
https://mp.weixin.qq.com/s/zCiZVxYR0HsglMVgJt9yNQ
网友评论