【问题标题】:generating a manhattan plot with ggplot用 ggplot 生成曼哈顿图
【发布时间】:2021-08-25 16:50:29
【问题描述】:

我一直在尝试使用 ggplot 生成曼哈顿图,我终于开始工作了。然而,尽管尝试了我在网上看到的几个不同的例子,但我无法得到染色体着色的点。我附上了我的代码和下面的结果图。谁能看到为什么代码无法按染色体着色点?

library(tidyverse)
library(vroom)

# threshold to drop really small -log10 p values so I don't have to plot millions of uninformative points. Just setting to 0 since I'm running for a small subset
min_p <- 0.0

# reading in data to brassica_df2, converting to data frame, removing characters from AvsDD p value column, converting to numeric, filtering by AvsDD (p value)
brassica_df2 <- vroom("manhattan_practice_data.txt", col_names = c("chromosome", "position", "num_SNPs", "prop_SNPs_coverage", "min_coverage", "AvsDD", "AvsWD", "DDvsWD"))
brassica_df2 <- as.data.frame(brassica_df2)
brassica_df2$AvsDD <- gsub("1:2=","",as.character(brassica_df2$AvsDD))
brassica_df2$AvsDD <- as.numeric(brassica_df2$AvsDD)
brassica_df2 <- filter(brassica_df2, AvsDD > min_p)

# setting significance threshhold
sig_cut <- -log10(1)

# settin ylim for graph
ylim <- (max(brassica_df2$AvsDD) + 2)

# setting up labels for x axis
axisdf <- as.data.frame(brassica_df2 %>% group_by(chromosome) %>% summarize(center=( max(position) + min(position) ) / 2 ))

# making manhattan plot of statistically significant SNP shifts 
manhplot <- ggplot(data = filter(brassica_df2, AvsDD > sig_cut), aes(x=position, y=AvsDD), color=as.factor(chromosome)) +
  geom_point(alpha = 0.8) +
  scale_x_continuous(label = axisdf$chromosome, breaks= axisdf$center) +
  scale_color_manual(values = rep(c("#276FBF", "#183059"), unique(length(axisdf$chromosome)))) +
  geom_hline(yintercept = sig_cut, lty = 2) +
  ylab("-log10 p value") +
  ylim(c(0,ylim)) +
  theme_classic() +
  theme(legend.position = "n")
print(manhplot)

【问题讨论】:

    标签: r ggplot2


    【解决方案1】:

    我认为您只需将您的 color=... 参数移到对 aes() 的调用中:

    ggplot(
        data = filter(brassica_df2, AvsDD > sig_cut),
        aes(x=position, y=AvsDD),
        color=as.factor(chromosome))
    

    变成……

    ggplot(
        data = filter(brassica_df2, AvsDD > sig_cut),
        aes(x=position, y=AvsDD, color=as.factor(chromosome)))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-29
      • 1970-01-01
      • 2012-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多