- 基本图像
# 添加均值线和轴须线
gghistogram(mtcars, x = "mpg",
fill = '#E7B800',
add = "mean",
rug = TRUE)
- 分组绘制直方图
mtcars$vs = as.factor(mtcars$vs)
gghistogram(mtcars, x = "mpg",
add = "mean",
rug = TRUE,
fill = "vs",
color = 'white',
palette = 'jco')
- 组合直方图和密度图
gghistogram(mtcars, x = "mpg",
add = "mean",
rug = TRUE,
fill = "vs",
palette = 'jco',
add_density = TRUE,
bins = 20)
- 分面
gghistogram(mtcars, x = "mpg",
add = "mean",
rug = TRUE,
fill = "vs",
color = 'white',
facet.by = 'vs',
add_density = TRUE,
palette = 'jco')