rggplot2phylogenyggtree

'Error: Must request at least one colour from a hue palette' when using ggtree


I am attempting to create a phylogeny tree that shows different coloured tip points for different dorsal patterns, when I first attempted this a few weeks ago it worked perfectly but trying it now I get the above error code. The only thing I have done differently since last time is updating some packages.

The code I am using is as follows:

ggtree(frogtree.2, layout="circular") %<+% frogdata + geom_tiplab(offset = .3, hjust = .6) + theme(legend.position = "right") + geom_tippoint(aes(colour=PATTERN))

Based from other queries on this error, I have no NAs in my data, the tree loads fine until I use geom_tippoint(aes(fill = PATTERN))

As this code has worked previously and I haven't changed the structure of the data (which is character and numerical) I am not sure where the problem lies.

Data snippet:

SPECIES MICROHABITAT COLOUR PATTERN
D. diastema WL Green Mottled
E. angustidigitorum Rock Green Uniform
E. antillensis Rock Green Uniform
E. atkinsi WL Brown Symmetrical
E. Campi Earth White Uniform
E. cooki Rock Brown Uniform

Thanks in advance.

Edit: From using dput my data snippet from 'frogdata' is:

>dput(frogdata[1:10, 1:4 ])
structure(list(SPECIES = c("D. diastema", "E. angustidigitorum", 
"E. antillensis", "E. atkinsi", "E. campi", "E. cooki", "E. coqui", 
"E. cystignathoides", "E. flavescens", "E. grandis"), FAMILY = c("Eleutherodactylidae ", 
"Eleutherodactylidae", "Eleutherodactylidae", "Eleutherodactylidae", 
"Eleutherodactylidae", "Eleutherodactylidae", "Eleutherodactylidae", 
"Eleutherodactylidae", "Eleutherodactylidae", "Eleutherodactylidae"
), MICROHABITAT = c("WL", "rock", "rock", "WL", "earth", "earth", 
"rock", "WL", "WL", "WL"), COLOUR = c("green", "green", "green", 
"brown", "white", "brown", "brown", "green", "green", "brown"
)), row.names = c(NA, 10L), class = "data.frame")

snippet from 'frogtree.2' is:

 dput(frogtree.2)
structure(list(edge = structure(c(97L, 97L, 96L, 96L, 95L, 95L, 
94L, 94L, 93L, 93L, 92L, 92L, 91L, 91L, 90L, 90L, 89L, 89L, 88L, 
88L, 87L, 87L, 86L, 86L, 85L, 85L, 84L, 84L, 83L, 83L, 82L, 82L, 
81L, 81L, 80L, 80L, 79L, 79L, 78L, 78L, 77L, 77L, 76L, 76L, 75L, 
75L, 74L, 74L, 73L, 73L, 72L, 72L, 71L, 71L, 70L, 70L, 69L, 69L, 
68L, 68L, 67L, 67L, 66L, 66L, 65L, 65L, 64L, 64L, 63L, 63L, 62L, 
62L, 61L, 61L, 60L, 60L, 59L, 59L, 58L, 58L, 57L, 57L, 56L, 56L, 
55L, 55L, 54L, 54L, 53L, 53L, 52L, 52L, 51L, 51L, 50L, 50L, 48L, 
49L, 47L, 97L, 45L, 46L, 95L, 96L, 44L, 94L, 41L, 42L, 92L, 43L, 
91L, 93L, 38L, 39L, 37L, 89L, 34L, 35L, 87L, 36L, 86L, 88L, 85L, 
40L, 84L, 90L, 32L, 33L, 31L, 82L, 28L, 29L, 27L, 80L, 24L, 25L, 
23L, 78L, 22L, 77L, 21L, 76L, 19L, 20L, 16L, 17L, 15L, 73L, 13L, 
14L, 12L, 71L, 10L, 11L, 69L, 70L, 9L, 68L, 7L, 8L, 5L, 6L, 3L, 
4L, 64L, 65L, 63L, 66L, 62L, 67L, 61L, 72L, 60L, 18L, 59L, 74L, 
58L, 75L, 57L, 26L, 56L, 79L, 55L, 30L, 54L, 81L, 53L, 83L, 1L, 
2L, 51L, 52L), .Dim = c(96L, 2L)), edge.length = c(0.03940155, 
0.03940155, 0.04827143, 0.00886988, 0.048902435, 0.048902435, 
0.0147448041666667, 0.0153758091666667, 0.066352673, 0.00270543383333331, 
0.02971821, 0.02971821, 0.00824750499999999, 0.037965715, 0.0608982058333334, 
0.0325112478333334, 0.026269995, 0.026269995, 0.0532619825, 0.0269919875, 
0.088415535, 0.088415535, 0.0125160194117647, 0.100931554411765, 
0, 0.0476695719117647, 0, 0.100931554411765, 0.0364101436041083, 
0.0384777771825397, 0.129893066666667, 0.129893066666667, 0.129893066666667, 
0, 0.06590009, 0.06590009, 0.071875705, 0.00597561499999999, 
0.037936535, 0.037936535, 0.0796354725, 0.0416989375, 0.0927819333333333, 
0.0131464608333333, 0.1262746025, 0.0334926691666667, 0.054465585, 
0.054465585, 0.03967896, 0.03967896, 0.058724815, 0.019045855, 
0.0171324, 0.0171324, 0.05103453, 0.03390213, 0.03775446, 0.03775446, 
0.0327989822727273, 0.0195189122727273, 0.0705534422727273, 0, 
0.027401475, 0.027401475, 0.025252155, 0.025252155, 0.015455835, 
0.015455835, 0.029841255, 0.020044935, 0.00717716249999999, 0.0250727775, 
0.0369889491666667, 0.0189097593939394, 0.0464202691666667, 0.0771586558333334, 
0.0416082706560284, 0.177491741489362, 0, 0.123026156489362, 
0.0396052220062134, 0.0908223609955752, 0, 0.217096963495575, 
0.0137432219084653, 0.15896448040404, 0, 0.23084018540404, 0.0170589140269943, 
0.118006032764368, 0, 0.110557401415162, 0.27845723, 0.27845723, 
0.239645341276596, 0.270203471845561), Nnode = 48L, node.label = c("Root", 
"1.0000", "", "0.1400", "0.0980", "0.2500", "0.9920", "0.5120", 
"0.2720", "0.3240", "0.7240", "0.9960", "0.9840", "0.7300", "0.5600", 
"1.0000", "0.9700", "0.6420", "0.7140", "0.9080", "0.7860", "0.9980", 
"0.9980", "0.9800", "0.9540", "0.8500", "0.6300", "0.8520", "0.9020", 
"0.9720", "0.5000", "0.1660", "0.2740", "0.3160", "0.1840", "0.0940", 
"0.2180", "0.4860", "0.3740", "0.9520", "0.6320", "1.0000", "0.7100", 
"0.4920", "0.5640", "0.6080", "0.5080", "0.8960"), tip.label = c("Pl._thaul", 
"En._petersi", "E._angustidigitorum", "E._grandis", "E._modestus", 
"E._pallidus", "E._nitidus", "E._pipilans", "E._longipes", "E._campi", 
"E._cystignathoides", "E._marnockii", "E._guttilatus", "E._verrucipes", 
"E._atkinsi", "E._planirostris", "E._rogersi", "E._inoptatus", 
"E._johnstonei", "E._martinicensis", "E._flavescens", "E._antillensis", 
"E._cooki", "E._coqui", "E._portoricensis", "D._diastema", "Pl._bufoninum", 
"Pl._cinereum", "Pl._brachyops", "Le._fragilis", "En._pustulosus", 
"Ph._cuvieri", "Ps._falcipes", "Ad._andreae", "Li._lineatus", 
"Le._wagneri", "Le._melanonotus", "Le._latrans", "Le._macrosternum", 
"Le._insularum", "Le._pentadactylus", "Le._savagei", "Le._knudseni", 
"Le._latinasus", "Le._albilabris", "Le._mystacinus", "Le._fuscus", 
"Le._gracilis", "Le._mystaceus")), class = "phylo", order = "postorder", RSS = 12.8678101120044)

This tree was imported as a newick file via

read.tree("frog.tree.nwk")

the packages I have tried using are:

library(tidyverse)
library(ape)
library(caper)
library(geiger)
library(maps)
library(phytools)
library(picante)
library(stringr)
library(adegenet)
library(stats)
library(ips)
library(phylobase)
library(ade4)
library(caper)
library(geiger)
library(phytools)
library(vegan)
library(lattice)
library(nlme)
library(MASS)
library(scales)
library(treeplyr)
library(phangorn)

UPDATE: So I am using the code that @Skaqqs provided:

```dat.1 <- data.frame(SPECIES = frogtree.2$tip.label, PATTERN = sample(frogdata$PATTERN, size = length(frogtree.2$tip.label), replace = T))```

This works with the ggtree code:

```ggtree(frogtree.2, layout="circular", branch.length = "none") %<+% dat.1 + geom_tiplab(offset = 7, hjust = .6) + geom_tippoint(aes(colour = PATTERN), cex = 4) + theme(legend.position = "right")```

But the dat.1 DF does not align with my data set and so the tree it produces is not valid. I also wanted to see if i could add REGION as a shape aesthetic to the tree using my data set (full dput output for entire DF):

```structure(list(SPECIES = structure(c(2L, 26L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L), .Label = c("Ad. Andreae", "D.diastema", "E. antillensis", "E. atkinsi", "E. campi", "E. cooki", "E. coqui", "E. cystignathoides","E. flavescens", "E. grandis", "E. guttilatus", "E. inoptatus", "E. johnstonei", "E. leprus", "E. longipes", "E. marnockii", "E. martinicensis", "E. modestus", "E. nitidus", "E. pallidus", "E. pipilans", "E. planirostris", "E. portoricensis", "E. rogersi", "E. verrucipes", "E.angustidigitorum", "En. petersi", "En. pustulosus", "Le. albilabris", "Le. fragilis", "Le. fuscus", "Le. iatrans", "Le. insularum", "Le. knudseni", "Le. latinasus", "Le. macrosternum", "Le. melanonotus", "Le. mystaceus ", "Le. mystacinus", "Le. pentadactylus", "Le. savagei", "Le. wagneri", "Le.gracilis", "Li. lineatus", "Ph. cuvieri", "Pl. brachyops", "Pl. bufoninum", "Pl. cinereum", "Pl. thaul", "Ps. falcipes"), class = "factor"), FAMILY = c("Eleutherodactylidae ", "Eleutherodactylidae", "Eleutherodactylidae", "Eleutherodactylidae", "Eleutherodactylidae", "Eleutherodactylidae", "Eleutherodactylidae", "Eleutherodactylidae", "Eleutherodactylidae", "Eleutherodactylidae"), MICROHABITAT = structure(c(7L, 4L, 4L, 7L, 1L, 1L, 4L, 7L, 7L, 7L), .Label = c("earth", "grass", "LL", "rock", "stones", "surface", "WL"), class = "factor"), COLOUR = structure(c(3L, 3L, 3L, 2L, 6L, 2L, 2L, 3L, 3L, 2L), .Label = c("beige", "brown", "green", "grey", "orange", "white"), class = "factor"), PATTERN = structure(c(3L, 5L, 5L, 4L, 5L, 5L, 4L, 3L, 2L, 3L), .Label = c("Barred", "Complex", "Mottled", "Symmetrical", "Uniform"), class = "factor"), COLOUR.1 = structure(c(7L, 3L, 6L, 3L, 4L, 3L, 1L, 1L, 10L, 9L), .Label = c("beige", "black", "brown", "green", "grey", "orange", "peach", "red", "rufous", "yellow"), class = "factor"), TONE = c(55.5, 56.3, 30.5, 31.9, 38.6, 33.9, 58.3, 45, 55.7, 58.7), DISTANCE = c(1187.23, 2185.09, 2024.26, 2285.65, 3172.5, 2039.48, 2216.22, 2264.15, 2113.5, 2147.5), REGION = structure(c(2L, 3L, 1L, 1L, 3L, 1L, 3L, 3L, 1L, 3L), .Label = c("Caribbean", "Central America", "North America", "Northern South America", "Southern South America"), class = "factor")), row.names = c(NA, 10L), class = "data.frame")```

I then created another DF from my data set:

```dat <- data.frame(SPECIES = frogdata$SPECIES, PATTERN = frogdata$PATTERN, REGION=frogdata$REGION)```

Plotted it with:

```ggtree(frogtree.2, layout="circular", branch.length = "none") %<+% dat + geom_tiplab(offset = 7, hjust = .6) + geom_tippoint(aes(colour = PATTERN, shape=REGION), cex = 4) + theme(legend.position = "right")```

But I get this warning message: Warning message:

```Removed 6 rows containing missing values (geom_point_g_gtree).```

And this figure:

https://i.sstatic.net/JxdCq.png

I can't see what would be wrong with my data set to get this warning code and the missing tip points, there are no NAs that I can see.


Solution

  • I think I figured out what is going on. If this doesn't fix the problem on your side, let me know and we can troubleshoot more. Are you sure you are using the full version of frogdata? If there are fewer species in frogdata than frogtree.2, I get an error:

    library(ggtree)
    
    # frogtree.2 <- data.frame(...)
    
    frogdata <- data.frame(
      SPECIES = c("D. diastema", "E. angustidigitorum", "E. antillensis", "E. atkinsi", "E. campi", "E. cooki", "E. coqui", "E. cystignathoides", "E. flavescens", "E. grandis"),
      FAMILY = c("Eleutherodactylidae ", "Eleutherodactylidae", "Eleutherodactylidae", "Eleutherodactylidae", "Eleutherodactylidae", "Eleutherodactylidae", "Eleutherodactylidae", "Eleutherodactylidae", "Eleutherodactylidae", "Eleutherodactylidae"),
      MICROHABITAT = c("WL", "rock", "rock", "WL", "earth", "earth", "rock", "WL", "WL", "WL"),
      COLOUR = c("green", "green", "green", "brown", "white", "brown", "brown", "green", "green", "brown"))
    
    # Add pattern field
    frogdata$PATTERN <- c("Mottled", "Uniform", "Uniform", "Symmetrical", "Uniform", "Uniform", "Blank", "Blank", "Blank", "Blank")
    
    # Plot fails
    ggtree(frogtree.2, layout="circular") %<+%
      frogdata +
      geom_tiplab(offset = .3, hjust = .6) +
      geom_tippoint(aes(colour = PATTERN)) +
      theme(legend.position = "right")
    #> Error: Must request at least one colour from a hue palette.
    

    But when I created an example dataset using all the species in your tree:

    # Create new frogdata with same number of species as frogtree.2
    dat <- data.frame(
      SPECIES = frogtree.2$tip.label,
      PATTERN = sample(frogdata$PATTERN, size = length(frogtree.2$tip.label), replace = TRUE))
    
    # New plot
    ggtree(frogtree.2, layout="circular") %<+%
      dat +
      geom_tiplab(offset = .3, hjust = .6) +
      geom_tippoint(aes(colour = PATTERN)) +
      theme(legend.position = "right")
    

    frogdata 2