![](/img/trans.png)
[英]ggstatsplot::ggbetweenstats: Increase font size in p-values in comparisons in R
[英]How to modify labels for p-values and size in ggstatsplot
我正在使用ggstatsplot
R
包進行繪圖。 完成劇情后,我有一個問題。 這是我的情節的代碼:
library(ggstatsplot)
#Data
data("movies_long")
movies_long
#Plot
Myplot <- ggbarstats(
data = movies_long,
x = mpaa,
y = year,
title = "Distribution of movies per year",
xlab = "year",
legend.title = "",
ggplot.component = list(ggplot2::scale_x_discrete(guide = ggplot2::guide_axis(n.dodge = 2))),
palette = "Set2"
)
接下來是輸出:
該情節非常有用,但有兩個問題。 首先是條形頂部的 p 值重疊。 其次是也有重疊的大小 n,我如何改進條形頂部的 p 值標簽以及底部的大小 n?
有沒有辦法使用置信度來獲取這些 p 值並轉換為 p<0.001、p<0.1?
非常感謝您的幫助。 在極端情況下,有沒有辦法知道如何計算每個條的 p 值(正在應用哪個測試),以便我可以復制它並使用ggplot2
創建類似的圖?
我質疑你的說法,即這個情節非常有用。 除了重疊標簽外,還有一些統計問題,包括:
這是限制在 1991 年至 2005 年之間發行的電影的相同情節。它更好,盡管仍然充滿了過多的未校正 p 值。
注意:我已經把地塊做得足夠大以容納所有這些標簽。 現在文本有點小,但通過一些試驗和錯誤,您可以得到“正確”的繪圖高度和寬度。
至於每個條形圖頂部的 p 值......有一種方便的方法可以提取在 ggplot 中可視化的數據:
p$data
#> # A tibble: 41 × 5
#> year mpaa counts perc .label
#> <fct> <fct> <int> <dbl> <chr>
#> 1 1991 R 5 83.3 83%
#> 2 1992 R 6 100 100%
#> 3 1993 R 5 83.3 83%
#> 4 1994 R 20 80 80%
#> 5 1995 R 59 69.4 69%
#> 6 1996 R 63 60.6 61%
#> 7 1997 R 71 62.3 62%
#> 8 1998 R 82 61.7 62%
#> 9 1999 R 98 61.3 61%
#> 10 2000 R 77 48.4 48%
#> # … with 31 more rows
現在我們已經確認每個條形圖都是按收視率(R、PG、PG-13)對電影數量的簡單匯總,我們可以快速檢查 p 值是否來自計數的卡方檢驗按評級:
p$data %>%
filter(
year == 2000
)
#> # A tibble: 3 × 5
#> year mpaa counts perc .label
#> <fct> <fct> <int> <dbl> <chr>
#> 1 2000 R 77 48.4 48%
#> 2 2000 PG-13 64 40.3 40%
#> 3 2000 PG 18 11.3 11%
chisq.test(c(77, 64, 18))
#>
#> Chi-squared test for given probabilities
#>
#> data: c(77, 64, 18)
#> X-squared = 36.264, df = 2, p-value = 1.335e-08
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.