R语言的ggpubr包画密度图
2020-11-08 本文已影响0人
灵活胖子的进步之路
library(foreign)
library(ggpubr)
washdata<-read.table("data.txt",header = T,sep = "\t")
washdata$age <-as.numeric(washdata$age)
washdata$SEX<-factor(washdata$SEX,labels=c("male","female"))
attach(washdata)#加载数据集,这样后续应用就方便了
ggdensity(washdata, x = "age", fill = "SEX", add = "median", rug = TRUE)
不同性别患者在不同年龄段的分布密度图
完整函数如下
ggdensity(data, x, y = "..density..", combine = FALSE, merge = FALSE,
color = "black", fill = NA, palette = NULL, size = NULL,
linetype = "solid", alpha = 0.5, title = NULL, xlab = NULL,
ylab = NULL, facet.by = NULL, panel.labs = NULL,
short.panel.labs = TRUE, add = c("none", "mean", "median"),
add.params = list(linetype = "dashed"), rug = FALSE, label = NULL,
font.label = list(size = 11, color = "black"), label.select = NULL,
repel = FALSE, label.rectangle = FALSE, ggtheme = theme_pubr(),
...)
R-everything 网址
https://rdrr.io/cran/ggpubr/man/ggdensity.html