R:在曼哈顿地块的X轴刻度线之间添加空格?

时间:2018-06-21 16:43:27

标签: r plot axis scatter-plot

我目前正在使用qqman R包来创建Manhattan情节:

library(qqman)
manhattan(gWasResults,cex.axis = 0.5)

enter image description here

但是我想像这样将每个染色体上的所有颜色更改为黑色:

manhattan(gWasResults,col = c("black","black"),cex.axis = 0.5)

enter image description here

如果我想在每个染色体之间增加间隔,以便您可以区分数据列或数据点属于哪个染色体,我可以在Manhattan模块中指定一个特定的绘图参数来执行此操作(例如,参见图片下面)?

enter image description here

1 个答案:

答案 0 :(得分:1)

一种替代方法是使用ggplot2。实际上,您为所需输出提供的示例图似乎是使用ggplot2创建的。

以下是两种解决方案:

a)使用抖动-geom_jitter

library(qqman)
library(ggplot2)

ggplot(data = gwasResults,
       aes(x = as.factor(CHR),
           y = -log10(P))) +
  geom_jitter(width = 0.2) + # adjusting width, impacts the spacing
  labs(x = "CHR") +
  # remove space between plot area and x axis
  scale_y_continuous(expand = c(0, 0.1))

enter image description here

b)使用构面-facet_grid

ggplot(data = gwasResults,
       aes(x = BP, 
           y = -log10(P))) +
  geom_point() +
  # remove space between plot area and x axis
  scale_y_continuous(expand = c(0, 0.1)) +
  # facet by CHR
  facet_grid(cols = vars(CHR),
             space = "free_x",
             scales = "free_x",
             switch = "x") +
  labs(x = "CHR") +
  theme(
    axis.text.x = element_blank(),
    axis.ticks.x = element_blank(),
    panel.grid = element_blank(),
    panel.spacing = unit(0.1, "cm") # adjust spacing between facets
  )

enter image description here