簡體   English   中英

重新定位 ggtree 上的標簽

[英]Reposition the labels on ggtree

我正在嘗試可視化我的 ggtree,但我似乎卡在了最后一步; 將樹標簽從水平重新定位到垂直,以便它們不重疊。 如果我更改 geom_tiplab 函數上的 geom = "text" ,我會得到我想要的但我的標簽不再着色。 這里這里的數據集

這是重現性的代碼; 請幫忙

p1 <- ape::read.tree("Tert_aln.fasta_processed.fa.raxml.support")
temp1 = read.csv("Tert_Final_Mapping_File.csv", sep=";")
mycolors = c(brewer.pal(name="Set1", n = 9), brewer.pal(name="Paired", n = 12), brewer.pal(name="Dark2", n = 8))
p2 <- ggtree(p1, layout='circular') %<+% temp1 +
  geom_tippoint(
    mapping = aes(color = phylum),          # tip color by phyla. 
    size = 2,
    show.legend = FALSE) +
  scale_color_manual(values = mycolors) +
  geom_tiplab(                          # adds name of phyla to tip of its branch
    aes(fill = phylum),
    color = 'black',                      
    offset = 2,
    size = 3,
    geom = "label",
    align = TRUE,
    face = "bold",
    label.size = 0
    label.padding = unit(0.15, "lines"), # amount of padding around the labels
    linetype = "solid") +
  ggtitle("Phylogenetic tree of Tert")+  # title of your graph
  theme(
    axis.title.x = element_blank(), # removes x-axis title
    axis.title.y = element_blank(), # removes y-axis title
    legend.title = element_text(    # defines font size and format of the legend title
      face = "bold",
      size = 12),   
    legend.text=element_text(       # defines font size and format of the legend text
      face = "bold",
      size = 10),  
    plot.title = element_text(      # defines font size and format of the plot title
      size = 12,
      face = "bold"),  
    legend.position = "bottom",     # defines placement of the legend
    legend.box = "vertical",        # defines placement of the legend
    legend.margin = margin()) 
pdf("ggplot_Tert1.pdf", width = 20, height = 22)
p2
dev.off()

我注意到你寫了你想要彩色標簽,但你有fill ,這在這里沒有做任何事情。 您還聲明了color = 'black'

對不起,如果我錯過了標記! 我正在應用我對你想看到的最好的猜測。

我做了四件事來實現這一目標:

    1. geom_tiplab() ,我fill = phylum更改color = phylum
    1. geom_tiplab() ,我注釋掉了color = 'black'
    1. geom_tiplab() ,我注釋掉了label.size = 0
    1. geom_tiplab() ,我geom = "label"更改geom = "text"

這是你想要的嗎? (您必須調整繪制的限制才能將所有文本放入視覺中。)這是geom = "text" 當您使用標簽時,它會自動旋轉值以水平顯示。

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM