美文网首页
二维核密度图(统计直方图)

二维核密度图(统计直方图)

作者: 余绕 | 来源:发表于2020-07-27 14:23 被阅读0次
library(RColorBrewer)
library(ggplot2)
colormap<-rev(brewer.pal(11,'Spectral'))
x1<-rnorm(mean = 2.3,7000)
y1<-rnorm(mean=1.2,7000)
df<-data.frame(x=x1,y=y1)
ggplot(df,aes(x,y))+geom_hex(bins=40,na.rm=TRUE)+#scale_fill_gradientn(colours=colormap)+theme_bw()
scale_fill_gradient2(low="Green",mid="LightGoldenrod1",high = "red",midpoint =10)+theme_bw() #自定义颜色,注意midpoint值要正确,否则颜色显示不全。


image.png

相关文章

网友评论

      本文标题:二维核密度图(统计直方图)

      本文链接:https://www.haomeiwen.com/subject/mhezlktx.html