简体   繁体   English

如何在 x 轴上制作 R plot 的 SNP,在 y 轴上制作信念?

[英]How to make an R plot of SNPs on the x-axis and beliefs on the y-axis?

How to make an R plot of SNPs on the x-axis and beliefs on the y-axis?如何在 x 轴上制作 R plot 的 SNP,在 y 轴上制作信念? Maybe a jitter plot?也许抖动 plot? Or an interactive plotly?还是交互式 plotly? If I were using Python, hash table would be the simplest data structure for this.如果我使用 Python,hash 表将是最简单的数据结构。 But it looks like R doesn't support such a data structure easily?但是貌似R不太容易支持这样的数据结构?

在此处输入图像描述

dput result: 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")

Following @akrun's first suggestion bel_bpa_df %>% unnest(SNPs) %>% mutate(SNPs = trimws(SNPs)) %>% ggplot(aes(SNPs, Belief)) + geom_jitter() , I got a plot that's pretty dense.按照@akrun 的第一个建议bel_bpa_df %>% unnest(SNPs) %>% mutate(SNPs = trimws(SNPs)) %>% ggplot(aes(SNPs, Belief)) + geom_jitter() ,我得到了一个非常密集的 plot。 I would be so good if I can look at the individual ids in the x-axis.如果我可以查看 x 轴上的各个 id,那就太好了。 Would plotly do a better job at this? plotly 在这方面会做得更好吗?

在此处输入图像描述

To answer your second question, you could rotate the x axis labels and change the font size using theme and guides (you could adjust the font size) like this:要回答第二个问题,您可以旋转 x 轴标签并使用themeguides更改字体大小(您可以调整字体大小),如下所示:

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))

Created on 2023-01-06 with reprex v2.0.2创建于 2023-01-06,使用reprex v2.0.2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM