我正在嘗試geom_point根據一個因素設定大小。我知道不建議這樣做,但我的資料非常不平衡(最小值為 6,最大值大于 10,000)。
我試圖使點的大小反映研究的總樣本量。我將總樣本量分為 6 個級別:小于 100;100 到 500;500 至 1,000;1,000 至 5,000;5,000 至 10,000;和超過 10,000。
這是我的嘗試:
rct_findings <- findings %>%
mutate(
Sample_Size_Range = case_when(
0 < Outcome_Sample_Size & Outcome_Sample_Size <= 100 ~ "0 < n <= 100",
100 < Outcome_Sample_Size & Outcome_Sample_Size <= 500 ~ "100 < n <= 500",
500 < Outcome_Sample_Size & Outcome_Sample_Size <= 1000 ~ "500 < n <= 1,000",
1000 < Outcome_Sample_Size & Outcome_Sample_Size <= 5000 ~ "1,000 < n <= 5,000",
5000 < Outcome_Sample_Size & Outcome_Sample_Size <= 10000 ~ "5,000 < n <= 10,000",
10000 < Outcome_Sample_Size ~ "10,000 < n"),
Sample_Size_Range = fct_relevel(Sample_Size_Range, c("0 < n <= 100", "100 < n <= 500", "500 < n <= 1,000", "1,000 < n <= 5,000", "5,000 < n <= 10,000", "10,000 < n")))
ggplot(rct_findings, aes(x = Effect_Size_Study, y = F_test_var_stat, size = as_factor(Sample_Size_Range)))
geom_point()
我得到的錯誤資訊是:
grid.Call.graphics(C_setviewport, vp, TRUE) 中的錯誤:視口的非有限位置和/或大小另外:警告訊息:1:不建議使用離散變數的大小。2:洗掉了 16 行包含缺失值 (geom_point)。
有人對如何解決這個問題有任何建議嗎?
uj5u.com熱心網友回復:
這似乎是大小分箱比例的一個很好的用例,您可以使用它完全規避將變數設定為一個因素。
library(ggplot2)
#> Warning: package 'ggplot2' was built under R version 4.1.1
# Dummy data
rct_findings <- data.frame(
Effect_Size_Study = rnorm(100),
F_test_var_stat = runif(100),
Outcome_Sample_Size = runif(100, min = 6, max = 10000)
)
ggplot(rct_findings, aes(x = Effect_Size_Study, y = F_test_var_stat))
geom_point(aes(size = Outcome_Sample_Size))
scale_size_binned_area(
limits = c(0, 10000),
breaks = c(0, 100, 500, 1000, 5000, 10000),
)

由reprex 包(v2.0.1)于 2021 年 12 月 14 日創建
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/381223.html
