我试图制作一个包含六个箱线图的图,
我不确定如何开始,但使用 ggplot
我希望连续获得 6 个箱线图:
A5
(1,0 和 NA)下三个变量的 3 个箱线图A9
(1、0 和 NA)下变量的 3 个箱线图。- 然后用 中的相应值填充箱线图
maf
。我一直在尝试绘制它们,但我只绘制了 Maf 列或灰色板。任何帮助都会很棒,谢谢。
A5 A9 maf
1 1 NA 9.33843e-01
2 1 1 2.07735e-01
3 1 1 9.28438e-01
4 1 1 7.17963e-01
5 0 NA 1.02935e-01
6 1 1 9.28281e-01
7 1 1 9.28100e-01
8 1 1 2.85170e-01
9 1 1 2.67085e-01
10 1 1 9.28339e-01
11 1 1 5.68334e-02
12 1 1 4.87848e-01
13 1 1 2.22414e-01
14 1 1 3.37689e-01
15 1 1 1.09452e-01
16 1 1 4.71361e-02
17 NA NA 6.87674e-01
18 0 0 5.03323e-01
19 1 1 8.93953e-01
20 1 1 9.13662e-01
编辑 - - - - - - - - - - - - - - - - - - - - - - - - - --------- 在原始资料上使用 e-9 指数运行代码时:
df %>%
pivot_longer(
-maf
) %>%
ggplot(aes(name, maf, fill=factor(value)))
geom_boxplot()
我得到这个影像:
编辑 2------------------------------------------------ -----------
structure(list(A5 = c(1L, 1L, 1L, 1L, 0L, 1L), A9 = c(NA, 1L,
1L, 1L, NA, 1L), maf = c("9.33843e-01", "2.07735e-01", "9.28438e-01",
"7.17963e-01", "1.02935e-01", "9.28281e-01")), row.names = c(NA,
6L), class = "data.frame")
uj5u.com热心网友回复:
更新新资料:
df %>%
pivot_longer(
-maf
) %>%
ggplot(aes(factor(name), as.numeric(maf), fill=factor(value)))
geom_boxplot()
scale_y_continuous(labels = function(x) format(x, scientific = FALSE))
第一个回答:
以长格式输入您的资料,然后使用 geom_boxplot()
library(tidyverse)
df %>%
pivot_longer(
-maf
) %>%
ggplot(aes(name, maf, fill=factor(value)))
geom_boxplot()
资料:
df <- structure(list(A5 = c(1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, NA, 0L, 1L, 1L), A9 = c(NA, 1L, 1L, 1L,
NA, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, NA, 0L, 1L, 1L
), maf = c(0.933843, 0.207735, 0.928438, 0.717963, 0.102935,
0.928281, 0.9281, 0.28517, 0.267085, 0.928339, 0.0568334, 0.487848,
0.222414, 0.337689, 0.109452, 0.0471361, 0.687674, 0.503323,
0.893953, 0.913662)), class = "data.frame", row.names = c("1",
"2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13",
"14", "15", "16", "17", "18", "19", "20"))
0 评论