如何根据 R 中导出图像中的热图来增加树状图的大小?

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

我在 R ggplot2 中制作了热图和相应的树状图。但是,我想知道如何增加导出的高分辨率图像的树状图的大小。 准确地说,我想增加两个树状图的宽度,以便可以正确地可视化图中元素之间的聚类。

数据:

> SampleDat
             CCC          CS        G1          G2          G3        LMS        USC
ASCL2          0  0.00000000 0.0000000  0.00000000  0.19791230  0.0000000 -0.2589399
THRB-AS1       0  0.15478030 0.0000000  0.15665590 -0.05063790  0.0000000 -0.1702256
ZFAND2A        0  0.37089000 0.4538498  0.00000000  0.34598680  0.0000000  0.3016402
C10orf82       0  0.13880730 0.0000000  0.15742300  0.18315680  0.0000000  0.1487810
ADAMTS16       0  0.18127015 0.0000000  0.17522080 -0.15981700  0.0000000  0.0000000
LOC107985287   0 -0.04640695 0.1287075  0.12656770  0.21860815 -0.3203314  0.3492471
LOC105375610   0  0.16883540 0.0000000  0.00000000  0.18512860 -0.3199183  0.0000000
LINC00485      0 -0.17285620 0.3035464 -0.10216190 -0.69079680 -0.1887855  0.0000000
PKMYT1         0  0.00000000 0.0000000  0.00000000  0.00000000 -0.3447935  0.0000000
TBX4           0  0.13699000 0.0000000  0.00000000  0.00000000  0.2159004  0.1126036
CNTN4          0  0.11820680 0.0000000  0.11894160  0.00000000  0.0000000  0.2915814
SUMF1          0  0.00000000 0.0000000  0.00000000  0.00000000 -0.6267713  0.0000000
SLC25A13       0 -0.09982340 0.2151051  0.09800212 -0.26193367  0.0000000 -0.3921427
LOC107984568   0  0.00000000 0.0000000  0.24254940 -0.05271005 -0.4876733  0.0000000
HS3ST2         0  0.14462475 0.0000000  0.10068490  0.00000000  0.1197004  0.1814833
C1orf141       0 -0.23244100 0.0000000  0.11186150 -0.07326740 -0.3609651  0.0000000
VGLL2          0  0.00000000 0.0000000 -0.23984550  0.10843580  0.2534536  0.0000000
REXO2          0  0.00000000 0.0000000  0.00000000 -0.53392505  0.0000000 -0.3302150
PAX6           0  0.22198410 0.0000000  0.19559730  0.00000000  0.2500406  0.0000000
H4C13          0  0.00000000 0.0000000  0.00000000  0.00000000  0.4118989  0.0000000

脚本:

library("readr")
library("dplyr")
library("ggh4x")
library("ggsci")
library("ggplot2")

    # Hierarchically cluster AllGrpDMRgene_mat
    SampleDat_yclus <- hclust(dist(SampleDat), "ave")
    SampleDat_xclus <- hclust(dist(t(SampleDat)), "ave")
    
    # Melting SampleDat
    SampleMelt <- data.frame(
      SYMBOL = rownames(SampleDat)[row(SampleDat)],
      Group = colnames(SampleDat)[col(SampleDat)],
      Mdiff = unname(do.call(c, SampleDat))
    )
    
    #mutating a new column for +ve and -ve
    Sample_Plotdat<-SampleMelt %>% 
      mutate(status = case_when(Mdiff < 0 ~ "low",
                                Mdiff > 0  ~ "high"))
    
    #making status as factor
    Sample_Plotdat$status<-as.factor(Sample_Plotdat$status)
    
    # Supply the clustering to the scales
    HeatDenTest<-ggplot(Sample_Plotdat, aes(Group, SYMBOL, fill = status)) +
      geom_raster() +
      xlab("Histological Groups") +
      ylab("Gene Symbol") +
      scale_fill_nejm(labels=c('Negative','Positive' ), name="")+
      scale_y_dendrogram(hclust = SampleDat_yclus) +
      scale_x_dendrogram(hclust = SampleDat_xclus, position = "top")+
      theme(axis.text.y = element_text(size=rel(.3), vjust = 0.5, hjust=1),
            axis.title.y = element_text(size=rel(4)),
            axis.ticks.y = element_blank(),
            axis.text.x = element_text(size=rel(3), vjust = 0.5, hjust=1),
            axis.title.x = element_text(size=rel(4)),
            legend.position = "bottom",
            legend.text=element_text(size=40),
            legend.key.size = unit(3, 'cm'))

 ggsave("HeatDenTest.jpeg", plot = HeatDenTest, width = 18, height =30, units = "in", dpi = 200)

原始绘图的尺寸相当大(宽度= 18,高度= 30,单位=“英寸”,dpi = 600),由于尺寸限制,此处显示了低分辨率绘图。

剧情:

r ggplot2 plot heatmap dendrogram
1个回答
0
投票

作为第一步,我建议坚持使用主题设置的默认字体大小,或者使用主题的

base_size=
参数全局设置基本字体大小,例如
theme_grey(base_size = ...)
。其次,在导出时,您可以使用例如来说明绘图的大小。
scale=
ggsave()
参数。最后,使用时
scale_x/y_dendrogram

树状图取代了轴刻度。 (参见文档

因此,您可以使用刻度线的主题选项来更改树状图的外观,例如

axis.ticks.length

library("ggh4x")
library("ggsci")
library("ggplot2")

HeatDenTest <- ggplot(Sample_Plotdat, aes(Group, SYMBOL, fill = status)) +
  geom_raster() +
  xlab("Histological Groups") +
  ylab("Gene Symbol") +
  scale_fill_nejm(labels = c("Negative", "Positive"), name = "") +
  scale_y_dendrogram(hclust = SampleDat_yclus) +
  scale_x_dendrogram(hclust = SampleDat_xclus, position = "top") +
  theme(
    axis.ticks.length = unit(5, "pt"),
    legend.position = "bottom",
  )
  
ggsave("HeatDenTest.jpeg",
  plot = HeatDenTest,
  width = 18, height = 30,
  units = "in", dpi = 200,
  scale = .25
)

© www.soinside.com 2019 - 2024. All rights reserved.