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