iman j
iman j

Reputation: 31

How to add p-value on boxplot using boxplot R command?

I used the boxplot function in R to make boxplots. And I want to add p-value in my boxplots. What should I do about it? There are methods used ggplot, but I don't want to use ggplot2. my code is :

boxplot(wbc~Vital_status,
        data=final_df$ximp,
        main="boxplots of wbc ",
        xlab="Vital status",
        ylab="wbc",
        col="orange",
        border="brown",
        outline=FALSE,boxwex=.5, xaxt='n', frame=FALSE
)
axis(side = 1,at = 0:3,labels=c("", "alive", "dead", ""),lwd.ticks = FALSE)

enter image description here

Upvotes: 1

Views: 775

Answers (1)

George
George

Reputation: 903

Either use mtextor text.

As you didn't provide final_df, I just used one of the examples

boxplot(len ~ dose:supp, data = ToothGrowth,
        boxwex = 0.5, col = c("orange", "yellow"),
        main = "Guinea Pigs' Tooth Growth",
        xlab = "Vitamin C dose mg", ylab = "tooth length",
        sep = ":", lex.order = TRUE, ylim = c(0, 35), yaxs = "i")
mtext("p=0.05", side=3)
text(x=3,y=30,labels="p=0.05")

Upvotes: 1

Related Questions