# 修改x轴区间个数:gghistogram(df1, x="weight", add = "mean", rug = TRUE, color = "sex", fill = "sex", palette = c("#00AFBB", "#E7B800"),bins = 50)
# 添加密度曲线gghistogram(df1, x = "weight", add ="mean", rug = TRUE, fill ="sex", palette = c("#00AFBB", "#E7B800"), add_density =TRUE)
# y 设置为密度gghistogram(df1, x = "weight", y = "..density..", add ="mean", rug = TRUE, fill ="sex", palette = c("#00AFBB", "#E7B800"), add_density =TRUE)
# 设置分组分面
gghistogram(df1, x = "weight", facet.by = "sex", add ="mean", rug = TRUE, fill ="sex", palette = c("#00AFBB", "#E7B800"), add_density =TRUE)
# 设置分面各组的标题
gghistogram(df1, x = "weight", facet.by = "sex", panel.labs = list(sex = c("Female", "Mmale")), add ="mean", rug = TRUE, fill ="sex", palette = c("#00AFBB", "#E7B800"), add_density =TRUE)
gghistogram 函数:
用法:
gghistogram(data, x, y = "..count..", combine = FALSE, merge = FALSE, color = "black", fill = NA, palette = NULL, size = NULL, linetype = "solid", alpha = 0.5, bins = NULL, binwidth = NULL, 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, add_density = FALSE, label = NULL, font.label = list(size = 11, color = "black"), label.select = NULL, repel = FALSE, label.rectangle = FALSE, ggtheme = theme_pubr(), ...)
参数:
data
所需的数据框(dataframe)
x
x轴作图所需的数据
y
设置为密度或count数("..density.." or "..count..")
combine
对于多个变量的数据是否分面。逻辑值,默认是FALSE。
merge
对于多个变量数据是否合并,默认是FALSE
color, fill
线条颜色与填充色
palette
自定义颜色画板
size
设置点和轮廓的大小
linetype
线条类型
alpha
透明度设置
bins
bin(x轴的区间)的个数,默认最高到30
binwidth
bin的宽度,数值在(0,1)
title
设置标题
xlab
设置x轴标题
ylab
设置y轴标题
facet.by
设置分组分面
panel.labs
设置分面各组的标题
short.panel.labs
是否缩写分面标题,逻辑值,默认是TRUE。
add
添加均值或中位数线("mean" or "median")
add.params
给add参数的对象添加其他参数/属性
rug
是否添加边际线
add_density
是否添加密度曲线
label
设置列标签
font.label
设置标签字体
repel
逻辑值,是否使用ggrepel避免字体重叠
label.rectangle
是否给标签添加方框
ggtheme
设置画图主题
柱状图
#先构建数据集
df2 <- data.frame(dose=c("D0.5", "D1", "D2"), len=c(4.2, 10, 29.5))head(df2)# dose len# 1 D0.5 4.2# 2 D1 10.0# 3 D2 29.5
# 柱状图基础版本:ggbarplot(df2, x = "dose", y = "len")
# 添加y的值作为标签ggbarplot(df2, x = "dose", y = "len", label = TRUE, label.pos = "out")
# 更改柱子的宽度ggbarplot(df2, x = "dose", y = "len", width = 0.5)