如何设置操作包

问题描述 投票:0回答:1

我试图找出分析来自同一矩阵的不同箱线图的独立组并避免facet_wrap2(其中数据太多) 我想独立地可视化每个氨基酸,例如仅 C8,然后是 C8_IS 等。或者甚至通过两个氨基酸组(例如 C8+C8_IS),然后滚动到 Orn + ORN_IS

以下脚本:

ggboxplot(intensity_test3, x = "sample", y = "Intensity", color = "day", palette = "lancet",
add="jitter", shape = "sample") + facet_grid2(~analyte~conc+method, margins = "vs", scales = "free")+
 theme_bw(base_size = 18)  +
 theme(strip.text.y = element_text(angle = 90))  + scale_y_continuous(labels = function(x) format(x, scientific = TRUE, accuracy = 1))

enter image description here

r facet-wrap manipulate
1个回答
0
投票

所以我只是编造了一些数据来匹配你的图表和代码。这是:

只需运行此代码即可获取我使用的数据集。

intensity_test3 <- structure(list(sample = c("Low_qc", "Low_qc", "Low_qc", "Low_qc", 
"Low_qc", "Low_qc", "Low_qc", "Low_qc", "Low_qc", "Low_qc", "Low_qc", 
"Low_qc", "Low_qc", "Low_qc", "Low_qc", "Low_qc", "Low_qc", "Low_qc", 
"Low_qc", "Low_qc", "Low_qc", "Low_qc", "Low_qc", "Low_qc", "Low_qc", 
"Low_qc", "Low_qc", "Low_qc", "Low_qc", "Low_qc", "Low_qc", "Low_qc", 
"high_qc", "high_qc", "high_qc", "high_qc", "high_qc", "high_qc", 
"high_qc", "high_qc", "high_qc", "high_qc", "high_qc", "high_qc", 
"high_qc", "high_qc", "high_qc", "high_qc", "high_qc", "high_qc", 
"high_qc", "high_qc", "high_qc", "high_qc", "high_qc", "high_qc", 
"high_qc", "high_qc", "high_qc", "high_qc", "high_qc", "high_qc", 
"high_qc", "high_qc"), Intensity = c(1e+05, 1e+05, 1e+05, 1e+05, 
1e+05, 1e+05, 1e+05, 1e+05, 1e+05, 1e+05, 1e+05, 1e+05, 1e+05, 
1e+05, 1e+05, 1e+05, 1e+05, 1e+05, 1e+05, 1e+05, 1e+05, 1e+05, 
1e+05, 1e+05, 1e+05, 1e+05, 1e+05, 1e+05, 1e+05, 1e+05, 1e+05, 
1e+05, 2e+05, 2e+05, 2e+05, 2e+05, 2e+05, 2e+05, 2e+05, 2e+05, 
2e+05, 2e+05, 2e+05, 2e+05, 2e+05, 2e+05, 2e+05, 2e+05, 2e+05, 
2e+05, 2e+05, 2e+05, 2e+05, 2e+05, 2e+05, 2e+05, 2e+05, 2e+05, 
2e+05, 2e+05, 2e+05, 2e+05, 2e+05, 2e+05), day = c("day_1", "day_1", 
"day_1", "day_1", "day_2", "day_2", "day_2", "day_2", "day_3", 
"day_3", "day_3", "day_3", "day_4", "day_4", "day_4", "day_4", 
"day_1", "day_1", "day_1", "day_1", "day_2", "day_2", "day_2", 
"day_2", "day_3", "day_3", "day_3", "day_3", "day_4", "day_4", 
"day_4", "day_4", "day_1", "day_1", "day_1", "day_1", "day_2", 
"day_2", "day_2", "day_2", "day_3", "day_3", "day_3", "day_3", 
"day_4", "day_4", "day_4", "day_4", "day_1", "day_1", "day_1", 
"day_1", "day_2", "day_2", "day_2", "day_2", "day_3", "day_3", 
"day_3", "day_3", "day_4", "day_4", "day_4", "day_4"), analyte = c("C8", 
"C8_I6", "orn", "orn_IS", "C8", "C8_I6", "orn", "orn_IS", "C8", 
"C8_I6", "om", "orn_IS", "C8", "C8_I6", "orn", "orn_IS", "C8", 
"C8_I6", "orn", "orn_IS", "C8", "C8_I6", "orn", "orn_IS", "C8", 
"C8_I6", "om", "orn_IS", "C8", "C8_I6", "orn", "orn_IS", "C8", 
"C8_I6", "orn", "orn_IS", "C8", "C8_I6", "orn", "orn_IS", "C8", 
"C8_I6", "om", "orn_IS", "C8", "C8_I6", "orn", "orn_IS", "C8", 
"C8_I6", "orn", "orn_IS", "C8", "C8_I6", "orn", "orn_IS", "C8", 
"C8_I6", "om", "orn_IS", "C8", "C8_I6", "orn", "orn_IS"), conc = c(2.7, 
2.7, 2.7, 2.7, 2.7, 2.7, 2.7, 2.7, 2.7, 2.7, 2.7, 2.7, 2.7, 2.7, 
2.7, 2.7, 8.1, 8.1, 8.1, 8.1, 8.1, 8.1, 8.1, 8.1, 8.1, 8.1, 8.1, 
8.1, 8.1, 8.1, 8.1, 8.1, 2.7, 2.7, 2.7, 2.7, 2.7, 2.7, 2.7, 2.7, 
2.7, 2.7, 2.7, 2.7, 2.7, 2.7, 2.7, 2.7, 8.1, 8.1, 8.1, 8.1, 8.1, 
8.1, 8.1, 8.1, 8.1, 8.1, 8.1, 8.1, 8.1, 8.1, 8.1, 8.1), method = c("new", 
"new", "new", "new", "new", "new", "new", "new", "new", "new", 
"new", "new", "new", "new", "new", "new", "old", "old", "old", 
"old", "old", "old", "old", "old", "old", "old", "old", "old", 
"old", "old", "old", "old", "new", "new", "new", "new", "new", 
"new", "new", "new", "new", "new", "new", "new", "new", "new", 
"new", "new", "old", "old", "old", "old", "old", "old", "old", 
"old", "old", "old", "old", "old", "old", "old", "old", "old"
)), class = "data.frame", row.names = c(NA, -64L))

然后我做了一个

for loop
filter
只运行每个
analyte
。它应该单独打印每个数字。您必须使用绘图查看器中的箭头才能在生成它们时查看它们(假设您使用的是 R studio)。如果您有任何疑问,或者这就是您正在寻找的内容,请告诉我。

for (i in unique(intensity_test3$analyte)){
  p <- ggboxplot(intensity_test3 %>% dplyr::filter(analyte %in% c(i)), x = "sample", y = "Intensity", color = "day", palette = "lancet",
            add="jitter", shape = "sample") + facet_grid2(~analyte~conc+method, margins = "vs", scales = "free")+
    theme_bw(base_size = 18)  +
    theme(strip.text.y = element_text(angle = 90))  + scale_y_continuous(labels = function(x) format(x, scientific = TRUE, accuracy = 1))
  print(p)
}

这是它制作的一个图形的示例。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.