ggplot:在geom_tile中,如何使用变量指定组,而不是x和y轴上的单个ID

问题描述 投票:0回答:1

我有一些这种形式的数据:

                                        ID2                                   ID1      value         pop1         pop2
1     16EME10-CP109-POOL_S1_L001_merged.bam 16EME10-CP109-POOL_S1_L001_merged.bam 0.00000000        Maine        Maine
2     16EME10-CP109-POOL_S1_L001_merged.bam        out_17SPL07-16-POOL-ExoSAP_S34 0.03231083        Maine        Maine
3     16EME10-CP109-POOL_S1_L001_merged.bam   17LHR07-57-POOL_S49_L001_merged.bam 0.03231083     Maryland        Maine
4     16EME10-CP109-POOL_S1_L001_merged.bam   17LHR07-53-POOL_S47_L001_merged.bam 0.03231083     Maryland        Maine
5     16EME10-CP109-POOL_S1_L001_merged.bam   17LHR07-30-POOL_S43_L001_merged.bam 0.03231083     Maryland        Maine
6     16EME10-CP109-POOL_S1_L001_merged.bam    18In08-39-POOL_S75_L001_merged.bam 0.00000000 Pennsylvania        Maine
7     16EME10-CP109-POOL_S1_L001_merged.bam        out_17SPL07-11-POOL-ExoSAP_S29 0.05430377        Maine        Maine
........

当我使用几何瓷砖绘制热图时:

ggplot(fstnewm, aes(ID1, ID2)) + 
  geom_tile(aes(fill = value), color =   "white") + 
  scale_fill_gradient(low = "red", high = "green") + 
  theme(axis.text.x = element_text(angle = 90)) 

放置轴的每个ID。我想使用pop1pop2对数据进行分组,同时保留单个图块,并在两个轴上都具有这些组。我假设我应该使用geom_text,但是我找不到方法。

编辑:Example graph在此图中,我想保留单个比较,但是在两个轴上都具有总体,而不是样本的ID。

r ggplot2 geom-text
1个回答
0
投票

您可以使用scale_x_discrete或/和scale_y_discrete来更改轴上的标签。

ggplot(fstnewm, aes(ID1, ID2)) + 
  geom_tile(aes(fill = value), color =   "white") + 
  scale_fill_gradient(low = "red", high = "green") + 
  theme(axis.text.x = element_text(angle = 90)) +
  scale_x_discrete(breaks = fstnewm$ID1,
                   labels = fstnewm$pop1) +
  scale_y_discrete(breaks = fstnewm$ID2,
                   labels = fstnewm$pop2)
© www.soinside.com 2019 - 2024. All rights reserved.