Hi,
I am trying to run a script from our group that has been used before to make a figure with the sample data I am using. I keep getting this error:
Error in `stat_tree()`:
! Problem while converting geom to grob.
ℹ Error occurred in the 1st layer.
Caused by error:
! Unknown colour name:
---
Backtrace:
▆
1. ├─ggplot2::ggsave(...)
2. │ ├─grid::grid.draw(plot)
3. │ └─ggplot2:::grid.draw.ggplot(plot)
4. │ ├─base::print(x)
5. │ └─ggplot2:::print.ggplot(x)
6. │ ├─ggplot2::ggplot_gtable(data)
7. │ └─ggplot2:::ggplot_gtable.ggplot_built(data)
8. │ └─ggplot2:::by_layer(...)
9. │ ├─rlang::try_fetch(...)
10. │ │ ├─base::tryCatch(...)
11. │ │ │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
12. │ │ │ └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
13. │ │ │ └─base (local) doTryCatch(return(expr), name, parentenv, handler)
14. │ │ └─base::withCallingHandlers(...)
15. │ └─ggplot2 (local) f(l = layers[[i]], d = data[[i]])
16. │ └─l$draw_geom(d, layout)
17. │ └─ggplot2 (local) draw_geom(..., self = self)
18. │ └─self$geom$draw_layer(...)
19. │ └─ggplot2 (local) draw_layer(..., self = self)
20. │ └─base::lapply(...)
21. │ └─ggplot2 (local) FUN(X[[i]], ...)
22. │ ├─rlang::inject(self$draw_panel(data, panel_params, coord, !!!params))
23. │ └─self$draw_panel(...)
24. │ └─ggplot2 (local) draw_panel(..., self = self)
25. │ └─GeomPath$draw_panel(...)
26. │ └─ggplot2 (local) draw_panel(..., self = self)
27. │ ├─grid::polylineGrob(...)
28. │ │ └─grid::grob(...)
29. │ ├─grid::gpar(...)
30. │ │ └─grid:::validGP(list(...))
31. │ │ └─grid (local) numnotnull("fontsize")
32. │ └─scales::alpha(munched$colour, munched$alpha)
33. │ └─farver::decode_colour(colour, alpha = TRUE)
34. │ └─farver:::decode_c(...)
35. └─base::.handleSimpleError(`<fn>`, "Unknown colour name: ", base::quote(NULL))
36. └─rlang (local) h(simpleError(msg, call))
37. └─handlers[[1L]](cnd)
38. └─cli::cli_abort(...)
39. └─rlang::abort(...)
No matter how I try to adapt my script the error persists. I feel like it might be a compatibilty issue between the version of R I have and the packages. I am running on version 4.3.2 but the error also occurs on version 4.3.3. I have the version of ggplot2 (3.5.0), ggtreeExtra (1.12.0), ggnewscale (0.4.10), ggtree (3.10.1).
Here is my script:
library(msaR)
library(msa)
library(rio)
library(seqinr)
library(ape)
library(ggtree)
library(ggplot2)
library(treeio)
library(ggnewscale)
library(ggstar)
library(ggtreeExtra)
library(scales)
library(Biostrings)
library(tidytree)
#Add dataframes
mySequences <- readAAStringSet('/Users/grahamscott/Documents/Phylogenetic-Tree-Sample/active_rAMPage.fasta')
sample_data <- import("/Users/grahamscott/Documents/Phylogenetic-Tree-Sample/pep_char.csv")
#Create MSA
activerAMPageMSA <- msa(mySequences)
#Convert MSA to distance alignment
rAMPage_converted <- msaConvert(activerAMPageMSA, type = 'seqinr::alignment')
d <- dist.alignment(rAMPage_converted, "identity")
#Create tree
d_matrix <- as.matrix(d)
tree <- nj(d_matrix)
#Convert tree to ggtree format
#tree is written and then read in order to convert from format used by ape into format used by ggtree
written_tree <- ape::write.tree(tree, 'active_rAMPage_tree')
converted_tree <- treeio::read.tree('active_rAMPage_tree')
converted_tree
#Tree with AMP names coloured by family membership and ring with colours depicting dataset origin
family_dataset_tree <- ggtree(converted_tree, layout='circular', size=0.2, options(ignore.negative.edge=TRUE)) %<+% sample_data +
aes(color = I(family))+
scale_color_manual(name = 'Family',
breaks = c("Nigrocin","Brevinin-1","Brevinin-2","Apidaecin","NA"),
labels = c("Nigrocin","Brevinin-1","Brevinin-2","Apidaecin","NA"),
values = c("#0992ad","#a30584","blue","#60a106","black"),
na.value = "black")+
new_scale_fill()+
geom_fruit(geom=geom_tile,
mapping=aes(fill=dataset),
width=0.02,
offset=0.25)+
scale_fill_manual(name = "Dataset",
breaks = c("Insect","Amphibian"),
labels = c("Insect","Amphibian"),
values = c("brown","#339900"))+
geom_tiplab(offset = 0.01, size=3.5)
#Above tree with BLASTp percent identity results added (percent identity to top hit)
blastp_tree <- family_dataset_tree +
new_scale_fill()+
geom_fruit(geom=geom_tile,
mapping=aes(fill=percent_identical),
width=0.02,
offset=0.05)+
scale_fill_gradient2(
name = "Percent Identity",
low = "#3ee6ca",
mid = "white",
high = "#031b54",
midpoint = 50
)
#Above tree with black/red dots at tip points depicting which are known AMPs
novel_tree <- blastp_tree +
new_scale_color() +
geom_tippoint(
mapping = aes(color= top_hit_known_amp),
size = 1.5
) +
scale_color_manual(
name = "Top Hit Antimicrobial",
breaks = c("yes","no"),
labels = c("yes","no"),
values = c("black","red")
)
#Above tree with distance scale
novel_tree + geom_treescale()
ggsave("Tree.pdf", height = 8.25, width = 8.25, units = "in", dpi=800)