如何绘制 x 轴上的 SNP 和 y 轴上的信念的 R 图?也许是抖动图?还是互动情节?如果我使用 Python,哈希表将是最简单的数据结构。但看起来 R 并不容易支持这样的数据结构?
dput
结果:
> dput(head(bel_bpa_df))
structure(list(SNPs = list(c("rs12117661 ", " rs11588151 ", " rs34232196 ",
" rs4500361 ", " rs4927191 ", " rs200159426 ", " rs187607506 ",
" rs12748266 ", " rs11206510 ", " rs34900073 ", " rs55958021 ",
" rs12404395 ", " rs613855 ", " rs624612 ", " rs625619 ", " rs479910"
), c("rs12117661 ", " rs11588151 ", " rs34232196 ", " rs3976734 ",
" rs4500361 ", " rs4927191 ", " rs200159426 ", " rs187607506 ",
" rs12748266 ", " rs11206510 ", " rs34900073 ", " rs2495491 ",
" rs2479415 ", " rs2495489 ", " rs55958021 ", " rs12404395 ",
" rs2479404 ", " rs2479409 ", " rs613855 ", " rs624612 ", " rs625619 ",
" rs479910"), c("rs12117661 ", " rs11588151 ", " rs34232196 ",
" rs4500361 ", " rs4927191 ", " rs200159426 ", " rs187607506 ",
" rs12748266 ", " rs11206510 ", " rs34900073 ", " rs55958021 ",
" rs12404395 ", " rs11206513 ", " rs7530425 ", " rs11436234 ",
" rs10888897 ", " rs7543163 ", " rs11206514 ", " rs11206515 ",
" rs10888898 ", " rs613855 ", " rs624612 ", " rs625619 ", " rs479910"
), c("rs12117661 ", " rs11588151 ", " rs34232196 ", " rs4500361 ",
" rs4927191 ", " rs200159426 ", " rs187607506 ", " rs12748266 ",
" rs11206510 ", " rs34900073 ", " rs55958021 ", " rs12404395 ",
" rs613855 ", " rs624612 ", " rs625619 ", " rs479910 ", " rs568052 ",
" rs483462 ", " rs615563 ", " rs630431 ", " rs662145 ", " 1:55539780_TA_T ",
" rs487230 ", " rs683880 ", " rs555687 ", " rs548852"), c("rs12117661 ",
" rs11588151 ", " rs34232196 ", " rs4500361 ", " rs4927191 ",
" rs200159426 ", " rs187607506 ", " rs12748266 ", " rs11206510 ",
" rs34900073 ", " rs55958021 ", " rs12404395 ", " rs613855 ",
" rs624612 ", " rs625619 ", " rs494198 ", " rs7552841 ", " rs639750 ",
" rs499883 ", " rs521662 ", " rs1165287 ", " rs634272 ", " rs553741 ",
" rs693668 ", " rs471705 ", " rs472495 ", " rs479910"), c("rs17111483 ",
" rs12117661 ", " rs11588151 ", " rs34232196 ", " rs4500361 ",
" rs4927191 ", " rs200159426 ", " rs199717562 ", " rs200730299 ",
" rs187607506 ", " rs60228221 ", " rs57498787 ", " rs12141643 ",
" rs4609471 ", " rs12748266 ", " rs11206510 ", " rs34900073 ",
" rs55958021 ", " rs12404395 ", " rs28385708 ", " rs613855 ",
" rs624612 ", " rs625619 ", " rs479910 ", " rs11206517 ", " rs12067569 ",
" rs10465832 ", " rs56235208 ", " rs72911441")), Belief = c(0.531441,
0.59049, 0.59049, 0.59049, 0.59049, 0.59049), Plausibility = c(1,
1, 1, 1, 1, 1), `Plty Ratio` = c(2.13420294989532, 2.4419428096994,
2.4419428096994, 2.4419428096994, 2.4419428096994, 2.4419428096994
)), row.names = c(NA, 6L), class = "data.frame")
按照@akrun 的第一个建议
bel_bpa_df %>% unnest(SNPs) %>% mutate(SNPs = trimws(SNPs)) %>% ggplot(aes(SNPs, Belief)) + geom_jitter()
,我得到了一个非常密集的情节。如果我可以查看 x 轴上的各个 id,那就太好了。会在这方面做得更好吗?
在@Quinten 的回答之后,我得到的情节具有任意顺序的 SNP 名称标签。如果有一个具有固定顺序的 SNP 名称的向量,我可以专门用那个顺序做一个图吗?
要回答您的第二个问题,您可以旋转 x 轴标签并使用
theme
和 guides
更改字体大小(您可以调整字体大小),如下所示:
library(dplyr)
library(tidyr)
library(ggplot2)
bel_bpa_df %>%
unnest(SNPs) %>%
mutate(SNPs = trimws(SNPs)) %>%
ggplot(aes(SNPs, Belief)) +
geom_jitter() +
guides(x = guide_axis(angle = 90)) +
theme(axis.text.x = element_text(size = 3))
创建于 2023-01-06 与 reprex v2.0.2