This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Adding p-value to box plot

I want to add p-value for box plots for independent two groups.

But the error said,,,

> p + stat_compare_means()
Don't know how to automatically pick scale for object of type quosure/formula. Defaulting to continuous.
Don't know how to automatically pick scale for object of type quosure/formula. Defaulting to continuous.
Error in validDetails.text(x) : 
  'pairlist' object cannot be coerced to type 'double'

Do you know how to resolve this? Maybe box plot does not show means, but I want to show p-value based on means?

Thank you in advance!!

r

Share an excerpt of the dataset and the code you are using.

How is your datatable ?

I used this some weeks ago:

ggplot(mean_expressed, aes(x = mean_expressed$variable, y = mean_expressed$value)) + 
  geom_boxplot(outlier.colour='black') + stat_compare_means(aes(group = mean_expressed$variable)

mean_expressed$variable is a qualitative variable that refers to groups to compare, and mean_expressed$value for the values

boxplot

Please use the formatting bar (especially the code option) to present your post better. You can use backticks for inline code (`text` becomes text), or select a chunk of text and use the highlighted button to format it as a code block. I've done it for you this time.
code_formatting

Try this.

stat_compare_means(aes(group = Data), label = "p.format")

Please use the formatting bar (especially the code option) to present your post better. You can use backticks for inline code (`text` becomes text), or select a chunk of text and use the highlighted button to format it as a code block. I've done it for you this time.
code_formatting

1 answer

Thank you so much for everybody! The codes you provided me did not work again, so I tried as below, which worked actually.

my_comparisons <- list( c("1", "2"), c("1", "3"), c("1", "4"),c("1", "5"), c("1", "7"), c("2", "3"), c("2", "4"), c("2", "5"), c("2", "7"), c("3", "4"), c("3", "5"), c("3", "7"), c("4", "5"), c("4", "7"), c("5", "7") )

ggboxplot(x, x = "B", y = "A", + color = "B", palette = "jco")+ + stat_compare_means(comparisons = my_comparisons)

Though this did not show the name of analysis (Kruscal Wallis) on the plot.

Thank you!!

Log in to answer this question.