library(ggstatsplot)
library(gapminder)
ggstatsplot::ggbetweenstats(
data = dplyr::filter(.data = gapminder, year == 2007),
x = continent,
y = lifeExp,
messages = FALSE)

library(ggpubr)
set.seed(1234)
df <- data.frame( sex=factor(rep(c("f", "M"), each=200)),
weight=c(rnorm(200, 55), rnorm(200, 58)))
ggdensity(df, x="weight", add = "mean", rug = TRUE, color = "sex", fill = "sex",
palette = c("#00AFBB", "#E7B800"))

require(ggplot2)
p <- ggplot(df, aes(weight, fill=sex, color=sex)) +
geom_density(alpha=.5) +
geom_rug()
print(p)

require(dplyr)
df2 = group_by(df, sex) %>% summarize(m = mean(weight))
p + geom_vline(aes(xintercept=m, color=sex), df2, linetype='dashed') +
scale_fill_manual(values=c("#00AFBB", "#E7B800")) +
scale_color_manual(values=c("#00AFBB", "#E7B800"))

library(ggstatsplot)
ggpiestats(data = mtcars,
main = am,
condition = cyl) +
scale_fill_brewer(palette = "Dark2")

ggbetweenstats(data = iris,
x = Species,
y = Sepal.Length)
[图片上传中...(image.png-64750e-1533376305494-0)]

ggscatterstats(data = iris,
x = Sepal.Length,
y = Petal.Length,
title = "Dataset: Iris flower data set")

ggscatterstats(data = iris,
x = Sepal.Length,
y = Petal.Length,
title = "Dataset: Iris flower data set",marginal.type = "density")

ggscatterstats(data = iris,
x = Sepal.Length,
y = Petal.Length,
title = "Dataset: Iris flower data set",marginal.type = "boxplot")

ggcorrmat(
data = subset(iris, Species == "versicolor"),
cor.vars = c(Sepal.Length, Sepal.Width, Petal.Length, Petal.Width))
参考链接:https://guangchuangyu.github.io/cn/2018/03/ggstatsplot/
网友评论