'troubleshooting ggtree to display node tip color and shape in accordance with external csv variables

i'm having a hard time getting my node tips on my tree to accommodate for species and host via tip color and tip shape. here is my code, the tree, and the csv data i am using to annotate the tree:

rm(list=ls())

#time to make Fig3A

library(ggplot2)
library(ggtree)
library(ape)

install.packages("devtools")
devtools::install_github("eliocamp/ggnewscale@dev")

install.packages("remotes")
remotes::install_github("emmanuelparadis/ape")

library(ggnewscale)

homewd= '/Users/mfv2446/Desktop/'

setwd(paste0(homewd))

#load the fig3a tree
treeC <- ape::read.tree('node_4_kobu.newick')

#load tree data prepared from elsewhere
dat <- read.csv(file = paste0(homewd, '/kobuviruses_taxid_194960.csv'), header = T, stringsAsFactors = F)

#species name
colz = c("Kobuvirus cattle/Kagoshima-2-24-KoV/2015/JPN" = "#CC79A7", "Aichivirus D"= "#E69F00", "Aichivirus B"="darkgoldenrod1", "Aichivirus A" = "black", "Canine kobuvirus" = "royalblue", "Caprine kobuvirus" = "tomato", "Marmot kobuvirus" = "mediumseagreen", "Aichivirus E" = "purple", "Ovine kobuvirus" = "green", "Kobuvirus sheep/TB3/HUN/2009" = "yellow",  "Mouse kobuvirus M-5/USA/2010" = "blue", "Aichivirus C" = "orange")

#pick order for the labels
dat$Species <- factor(dat$Species, levels =c("Kobuvirus cattle/Kagoshima-2-24-KoV/2015/JPN", "Aichivirus D", "Aichivirus B", "Aichivirus A", "Canine kobuvirus", "Caprine kobuvirus", "Marmot kobuvirus", "Aichivirus E", "Ovine kobuvirus", "Kobuvirus sheep/TB3/HUN/2009", "Mouse kobuvirus M-5/USA/2010", "Aichivirus C")

#take a glance
ggtree(treeC) %<+% dat2 + geom_tippoint(aes(fill=Species, shape=Host), shape=21) + geom_tiplab(linesize= 0.1, size=2.5) + 
   geom_nodelab(size=1, nudge_x = -0.01, nudge_y = 0.25) + scale_fill_manual(values=colz) + 
   theme(legend.position = c(.2,.85), legend.title = element_blank())

tree

csv data



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source