ggplot2: 密度图

绘制密度图

ggplot() + geom_density(data=, aes(x=), color=, fill=)
ggplot() + geom_density(data=, aes(x=, color=), size=)
ggplot() + geom_density(data=, aes(x=, fill=), alpha=)

    1. color=: 轮廓颜色
    1. fill=: 填充颜色
    1. size=: 线宽度
    1. alpha=: 填充颜色的透明度,0为完全透明,1为完全不透明

1. 简单密度图(仅一组数据)

kk <- as.data.frame(rnorm(10000))
colnames(kk) <- "pp"
ggplot()+geom_density(data=kk, aes(x=pp), color = "black", fill = "gray")  '#示例一
ggplot()+geom_density(data=kk, aes(x=pp), color = "black", fill = "gray")+theme_classic()  #示例二
示例一

示例二

2. 组合密度(两组或者以上数据)

kk <- as.data.frame(rnorm(10000))
kk[,2] <- "type_1"
colnames(kk) <- c("column_1", "column_2")

pp <- as.data.frame(rnorm(7000)+2)
pp[,2] <- "type_2"
colnames(pp) <- c("column_1", "column_2")

ff <- as.data.frame(rnorm(8000)-3)
ff[,2] <- "type_3"
colnames(ff) <- c("column_1", "column_2")

tt <- rbind(kk, pp, ff)
tt[,2] <- as.factor(tt[,2])

ggplot()+geom_density(data = tt, aes(x=column_1, color=column_2), size=1.5)   '#示例三
ggplot()+geom_density(data = tt, aes(x=column_1, fill=column_2), alpha=0.3)  #示例四
示例 三

示例四
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 作者:严涛浙江大学作物遗传育种在读研究生(生物信息学方向)伪码农,R语言爱好者,爱开源 ggplot2学习笔记之图...
    Dylan的迪阅读 3,002评论 0赞 6
  • 图形属性 x y xmin xmax ymin ymax xend yend weight color:轮廓色 f...
    Liam_ml阅读 7,570评论 0赞 5
  • 本文讲述如何利用ggplot2绘制密度图和直方图 准备数据: set.seed(1126) #设置随机种子,让结果...
    钿璎纍纍佩珊珊阅读 2,975评论 0赞 4
  • 一.基本概念 "一张统计图形就是从数据到几何对象(geometric object, 缩写为geom, 包括点、线...
    apricoter阅读 53,821评论 6赞 173
  • !备忘,方便自己查询,随着使用更新,无参考价值。 Function reference[https://ggplo...
    shwzhao阅读 1,305评论 0赞 7

友情链接更多精彩内容