[英]Add patterns to boxplots in r
早上好,
我正在尋找一種在我的 r boxplots 上添加模式的方法。 我已經看到一些解決方案已經存在(例如在這里),但我也找到了一種更直接的方法來做到這一點( 在這里)。 但是,我無法重現此處給出的示例。
structure(list(day = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("d0",
"db"), class = "factor"), name = structure(1:20, .Label = c("x1",
"x2", "x3", "x4", "x5",
"x6", "x7", "x8", "x9",
"x10", "x11", "x12", "x13",
"x14", "x15", "x16", "x17",
"x18", "x19", "x20", "x21", "x22",
"x23", "x24", "x25", "x26",
"x27", "x28", "x29", "x30",
"x31", "x32", "x33", "x34",
"x35", "x36", "x37", "x38", "x39"
), class = "factor"), mean = c(36.6, 36.2636363636364, 36.9285714285714,
35.325, 37.0692307692308, 37.2357142857143, 36.85, 36.0153846153846,
35.6384615384615, 36.76, 36.8538461538462, 35.4307692307692,
35.3, 36.8153846153846, 36.1666666666667, 37.775, 37.3733333333333,
36.4666666666667, 36.6071428571429, 36.6)), row.names = c(NA,
-20L), class = c("grouped_df", "tbl_df", "tbl", "data.frame"), vars = "day", drop = TRUE, indices = list(
0:19), group_sizes = 20L, biggest_group_size = 20L, labels = structure(list(
day = structure(1L, .Label = c("d0", "db"), class = "factor")), row.names = c(NA,
-1L), class = "data.frame", vars = "day", drop = TRUE))
到目前為止,我所擁有的是以下幾行:
patternboxplot(data=temp_mean, x=temp_mean$day, y = temp_mean$mean, group = NULL,
pattern.type = c('nwlines', 'blank'), pattern.line.size = c(6,1),
pattern.color = c('black', 'white'),
background.color = c('white', 'white'),
frame.color = c('black', 'black'),
density=c(6,1))
運行它時,我收到以下錯誤:
“在 imagetodf2(readPNG(paste(location, "/", pattern.type[i], ".png", : object 'xmin' not found) 中出錯"。
如果有人對此有所了解,我會很高興聽到它!
先感謝您。
編輯:我想繪制下圖(使用完全相同的數據集和gglpot2
包在此處獲得)
模擬類似你的數據的東西:
temp_mean = data.frame(
day = sample(c("d0","db"),100,replace=TRUE),
mean = rnorm(100)
)
我嘗試過但無法讓它們具有不同的填充,每個 x 軸中斷組。 您可以嘗試以下操作(可能不理想):
patternboxplot(data=temp_mean, x=1, y = temp_mean$mean, group = temp_mean$day,
pattern.type = c('nwlines', 'blank'), pattern.line.size = c(6,1),
pattern.color = c('black', 'white'),
background.color = c('white', 'white'),
frame.color = c('black', 'black'),
density=c(6,1),
legend.h=30,legend.w=0.05,legend.x.pos=1.075,
legend.y.pos=0.88,
legend.pixel=10)
這不會崩潰,但是您必須自己體驗自己喜歡的模式。
patternboxplot(data=temp_mean, x=factor(temp_mean$day), y = as.numeric(temp_mean$mean),group=NULL,
pattern.type = c('nwlines'), pattern.line.size = c(6,1),
pattern.color = c('black'),
background.color = c('white'),
frame.color = c('black'),
density=c(6,1))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.