I am trying to visualize my ggtree and I seem to be stuck on the last final step; repositioning the tree labels from horizontal to verticle so that they do not overlap. If I change the geom = "text" on the geom_tiplab function, I get what I want but my labels are no longer coloured. Datasets here and here
Here is the code for reproducibility; Please help
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()
I noticed you wrote you wanted colored labels, but you have fill
, which isn't doing anything here. You declared color = 'black'
, as well.
Sorry if I miss the mark! I am applying my best guess as to what you wanted to see.
There are four things I did to make this happen:
geom_tiplab()
, I changed fill = phylum
to color = phylum
.geom_tiplab()
, I commented out color = 'black'
.geom_tiplab()
, I commented out label.size = 0
.geom_tiplab()
, I changed geom = "label"
to geom = "text"
.Is this what you wanted? (You will have to adjust the plotted limits to get all of the text into the visual.) This is geom = "text"
. When you use labels, it automatically rotates the values to show horizontally.