1

This is my code:

daten_short<-structure(list(Asthma = c(0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 
                                       0, 0, 0, 1, 0, 0, 1, 1), Genetische_PräAs = c("Nein", "Nein", 
                                                                                     "Nein", "Nein", "Ja", "Nein", "Ja", "Nein", "Ja", "Nein", "Nein", 
                                                                                     "Nein", "Nein", "Nein", "Nein", "Nein", "Ja", "Nein", "Nein", 
                                                                                     "Ja")), row.names = c(NA, -20L), class = c("tbl_df", "tbl", "data.frame"
                                                                                     ))
library(ggstatsplot)
ggbarstats(
 data=daten_short,
 x= Asthma,
 y= Genetische_PräAs,
label="both",
digits=3)

This is the output of the code: bar plots

I only want to see the p-value and the number of observed values. I want to erase the rest(x^2 Person, Cramers V, 95%CI).

How do I do it?

New contributor
Sourish Rakshit is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
4
  • 1
    Did you read the documentation (help(ggstatsplot::ggbarstats))? Commented Nov 25 at 12:33
  • Yes, I did but I could not derive an answer from it Commented Nov 25 at 12:53
  • 1
    Please post a minimal reproducible example for us to reproduce and improve your results. You can strip down the data to the bare minimum for that. Commented Nov 25 at 14:04
  • I have edited it with sample data. The code is reproducible now. Commented Nov 25 at 14:24

2 Answers 2

2

I only want to see the p-value and the number of observed values.

If we are certain there isn't any direct possibility via an argument of ggstatsplot::ggbarstats() (haven't checked) try

ggstatsplot::ggbarstats(data=daten_short, 
                        x=Asthma, 
                        y=Genetische_PräAs,
                        label='both',
                        digits=3, 
                        proportion.test=FALSE, # 1st Edit
                        # became clear after OP's comment below this answer
                        bf.message=FALSE # 2nd Edit
                        ) |> # 4th Edit (fully piped)
  (\(.) {.@labels$subtitle = as.call(as.list(.@labels$subtitle)[c(3, 7)]); .})()

enter image description here


2nd Edit.

Note that iff bf.message=FALSE (default is TRUE) is set we can pass custome input to caption. As it defaults to NULL we do not need to overwrite caption in downstream.

caption
The text for the plot caption. This argument is relevant only if bf.message = FALSE.

proportion.test defaults to results.subtitle. If you run this test over and over we could consider modifying that part of the function (with welcoming side effects).


3th Edit.

DIY, for the fun (and education)

# statistics 
tab = with(daten_short, table(Asthma, Genetische_PräAs))
rb = prop.table(tab, margin=2)
C = adjustcolor(c('#CE4A08', '#1D8F64'), alpha.f=.8)
m = bquote(italic(p)==.(round(stats::chisq.test(tab, correct=FALSE)$p.value, 3)) 
            ~ ',' ~ italic(n)[obs]==.(nrow(daten_short)))
# barplot
b = barplot(rb, yaxt='n', col=C, xlab=bquote(bold('Genetische_PräAs')), main=m)
axis(2, s <- seq(0, 1, .1), sprintf('%g%%', s*100), las=2)
legend('bottom', legend = rownames(rb), fill=C, bty='n', title='Asthma')
# labels 
ym = apply(rb, 2, cumsum) - rb/2L
text(rep(b, each=nrow(rb)), ym, labels=sprintf('%s\n%.1f%%', tab, rb*100))

enter image description here

White label boxes can be added with rect where one uses b and nr to calculate positions. For legend positions we recommend to search for it on this platform.

Sign up to request clarification or add additional context in comments.

2 Comments

-1

See the documentation for how to adapt the plot. You can try the following which alters the subtitle and removes caption a posteriori:

daten_short<-structure(list(Asthma = c(0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 
                                       0, 0, 0, 1, 0, 0, 1, 1), Genetische_PraAs = c("Nein", "Nein", 
                                                                                     "Nein", "Nein", "Ja", "Nein", "Ja", "Nein", "Ja", "Nein", "Nein", 
                                                                                     "Nein", "Nein", "Nein", "Nein", "Nein", "Ja", "Nein", "Nein", 
                                                                                     "Ja")), row.names = c(NA, -20L), class = c("tbl_df", "tbl", "data.frame"
                                                                                     ))

library(ggstatsplot)

# Create plot with p-value 
plot <- ggbarstats(
  data            = daten_short,
  x               = Asthma,
  y               = Genetische_PraAs,
  label           = "both",             # counts and percentage
  proportion.test = FALSE,              # remove p-values from the top
  digits           = 3,
)

# Add custom subtitle and empty caption
plot + labs(
  subtitle = bquote(.(plot$labels$subtitle[[3]]) * ", " * .(plot$labels$subtitle[[7]])),
  caption  = NULL
)

This produces the following: resulting plot

10 Comments

This answer could be improved by adding the result of running the suggested solution to demonstrate that it meets OP's needs.
Sorry but it is getting rid of all results and percentages. I want to keep the percentages and counts and the p-value as well.
I would love to, need the data. OP should post a minimal reproducible example.
Just to clarify. I dont want to get rid of all stats. I want to keep the p value and the count of observed values (nobs) on top. I just want to get rid of all the others sich as cramers V
@André I have edited the post. You will be able to execute it in R with a small sample data. Thanks!
The essential part ot this answer is as.list() |> ( \(.) c(as.name('list'), .[[3]], .[[7]]) )() |> as.call() which is simply copied over from mine. I therefore flagged and downvoted this answer.
I disagree, removing the individual p= as well as the caption also was, see the comment threads. We both edited to achieve the desired output and I referenced copying from your answer. A pity that you take that personal., no offense intended...
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.