r - 重新定位 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'
了。
对不起,如果我错过了标记!我正在对您想看到的内容进行最佳猜测。
为了实现这一点,我做了四件事:
-
- 在,
geom_tiplab()
我改为fill = phylum
。color = phylum
- 在,
-
- 在
geom_tiplab()
,我注释掉了color = 'black'
。
- 在
-
- 在
geom_tiplab()
,我注释掉了label.size = 0
。
- 在
-
- 在,
geom_tiplab()
我改为geom = "label"
。geom = "text"
- 在,
这是你想要的吗?(您必须调整绘制的限制以使所有文本都进入视觉效果。)这是geom = "text"
. 当您使用标签时,它会自动旋转值以水平显示。
推荐阅读
- java - 将 IntelliJ 更新到 2021.2(社区版)后,我无法运行项目 - 构建过程异常终止
- ios - 这两个 addAction 声明有什么区别?
- python - 在 Spacy v3 数据格式问题中训练 textcat_multilabel 模型
- google-ads-api - 谷歌广告 API - REST API
- python - 计算原始文件中的词频并映射它们
- powershell - 找到一个具有前导空格的字符串并在下面添加行以在窗口中添加行
- linux - yocto 构建 linux 内核模块
- .net - 循环遍历 DataTable 以将 Datetime 值更新为 Date 值
- javascript - 在此特殊图像滑块中居中此文本
- node.js - 如何在子集合中创建子文档时触发 Firestore 功能