# How to mark pvalue significance in R language?

Time：2021-11-9

Author: a cat that wants to fly
Reviewer: Tong Meng
Edit: Angelica

Box graph is one of the most common graphs in statistics. This article will describe how to simply compare the average values of two or more groups and add significance markers.

Generally, it can be divided into four categories according to the value of significance p value:
（1）0.01≤p<0.05，*
（2）0.001≤p<0.01，**
（3）0.0001≤p<0.001，***
（4）p<0.0001, ****
Next, we will describe three ways to add significance markers.

## Method 1 – add manually

1: Create data and draw box diagram.

``````library(ggplot2)
ggplot(iris, aes(x=Species, y=Sepal.Length))+geom_boxplot()
`````` ``````library(ggplot2)
###Sets the position of the four points of the horizontal line
df2 <- data.frame(a = c(2,2,3,3), b = c(8,8.1,8.1,8))
ggplot(iris, aes(x=Species, y=Sepal.Length))+
geom_boxplot()+
###Draw the line according to the set position
geom_line(data = df2, aes(x = a, y = b)) +
annotate("text", x = 2.5, y = 8.2, label = "***", size = 8)`````` The disadvantage of this method is that when adding significance manually, it is necessary to confirm the p value of significance.

## Method 2 – use ggsign

``````install.packages("ggsignif")
``````

2: Create data and draw box diagram.

``````library(ggplot2)
library(ggsignif)
ggplot(iris, aes(x=Species, y=Sepal.Length)) +
geom_boxplot()
`````` 3: Use the ggsign R package to add significance markers.

``````library(ggplot2)
library(ggsignif)
ggplot(iris, aes(x=Species, y=Sepal.Length)) +
geom_boxplot() +
geom_signif(comparisons = list(c("versicolor", "virginica")),
###P value < 0.05
map_signif_level=TRUE)`````` ## Method 3 – use ggpubr

``````install.packages("ggpubr")
``````

2: Create data and draw box diagram.

``````library(ggpubr)
###Add a list of pairwise comparisons
my_comparisons <- list(c("setosa", "versicolor"), c("setosa", "virginica"), c("versicolor", "virginica"))
ggboxplot(iris, x="Species", y="Sepal.Length",color = "Species",palette = "jco", add = "jitter")`````` 3: Use the ggpubr R package to add significance markers.

``````library(ggpubr)
my_comparisons <- list(c("setosa", "versicolor"), c("setosa", "virginica"), c("versicolor", "virginica"))
ggboxplot(iris, x="Species", y="Sepal.Length",color = "Species",palette = "jco", add = "jitter")+
###Add the statistical results of multi group comparison
stat_compare_means(label.y = 9.5)+
###Add significance marker location information for each pairwise comparison
stat_compare_means(comparisons=my_comparisons, label.y = c(7.6, 8.4, 8.0), label ="p.signif")`````` The R package can increase the p-value value between multiple groups and the comparison between specified groups.

I believe you have learned about the three methods of adding. If you have any better methods or other things you want to share, you are also welcome to contribute to us.

## Why is reids fast

1. What is redis? Redis is completely open source and complies with the BSD protocol. It is a high-performance key value database. Redis is also one of the most popular NoSQL databases at present. It contains a variety of data structures, supports network, is memory based, and has an optional key value pair storage database […]