我有一些这种形式的数据:
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。我想使用pop1
和pop2
对数据进行分组,同时保留单个图块,并在两个轴上都具有这些组。我假设我应该使用geom_text
,但是我找不到方法。
编辑:Example graph在此图中,我想保留单个比较,但是在两个轴上都具有总体,而不是样本的ID。
您可以使用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)