TVP

# 组间差异分析就要这样可视化！

3590

https://cran.r-project.org/web/packages/ggsignif/vignettes/intro.html

``````> library(ggplot2)
> library(ggsignif)
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1          5.1         3.5          1.4         0.2  setosa
2          4.9         3.0          1.4         0.2  setosa
3          4.7         3.2          1.3         0.2  setosa
4          4.6         3.1          1.5         0.2  setosa
5          5.0         3.6          1.4         0.2  setosa
6          5.4         3.9          1.7         0.4  setosa
> ggplot(iris, aes(x = Species, y = Sepal.Length)) +
+   geom_boxplot() +
+   geom_signif(
+     comparisons = list(c("versicolor", "virginica"))
+ )``````

``````> ggplot(iris, aes(x = Species, y = Sepal.Length)) +
+   geom_boxplot() +
+   geom_signif(
+     comparisons = list(
+       c("versicolor", "virginica"),
+       c("setosa", "virginica"),
+       c("setosa", "versicolor")
+     )
+ )``````

``````> ggplot(iris, aes(x = Species, y = Sepal.Length)) +
+   geom_boxplot() +
+   geom_signif(
+     annotations = c("First", "Second", "Third"),
+     y_position = c(8, 8.2, 8.5),
+     xmin = c(1, 2, 1),
+     xmax = c(2, 3, 3)
+ )``````

``````> data <- iris[iris\$Species %in% c("versicolor", "virginica"), ]
> ggplot(data, aes(x = Species, y = Sepal.Length, fill = Species)) +
+   geom_boxplot() +
+   geom_signif(comparisons = list(c("versicolor", "virginica"))) +
+   theme_classic() +
+   theme(legend.position = "top")``````

``````> ggplot(data, aes(x = Species, y = Sepal.Length, fill = Species)) +
+   geom_boxplot() +
+   geom_signif(comparisons = list(c("versicolor", "virginica"))) +
+   theme_classic() +
+   theme(legend.position = "top")
> ggplot(iris, aes(x = Species, y = Sepal.Length, fill = Species)) +
+   geom_boxplot() +
+   geom_signif(
+     annotations = c("*", "**", "***"),
+     y_position = c(8, 8.2, 8.5),
+     xmin = c(1, 2, 1),
+     xmax = c(2, 3, 3)
+   ) +
+   theme_classic() +
+   theme(legend.position = "top")``````

·end·

0 条评论