0

I am trying to produce a plot containing two figures: (1) a phylogenetic tree on the left, and (2) a horizontal stacked bar graph on the right.

library(ggtree)
library(tidyverse)
library(clustree)

p <- ggtree(vtree) + geom_blank(aes(x=0.42))

facet_plot(p, data = mytable2, geom = geom_bar, panel = "Cluster", colour = "black",
           mapping = aes(x=Freq, fill=clusterCut), stat = "identity", orientation="y") +
  geom_tiplab(size = 2) 

But, when I run the code above, I get the following error:

Error:
! Problem while computing aesthetics.
ℹ Error occurred in the 4th layer.
Caused by error in `FUN()`:
! object 'clusterCut' not found
---
Backtrace:
  1. base (local) `<fn>`(x)
  2. ggplot2:::print.ggplot(x)
  4. ggplot2:::ggplot_build.ggplot(x)
  5. ggplot2:::by_layer(...)
 12. ggplot2 (local) f(l = layers[[i]], d = data[[i]])
 13. l$compute_aesthetics(d, plot)
 14. ggplot2 (local) compute_aesthetics(..., self = self)
 15. ggplot2:::scales_add_defaults(...)
 16. base::lapply(aesthetics[new_aesthetics], eval_tidy, data = data)
 17. rlang (local) FUN(X[[i]], ...)

I'm having trouble understanding the error notice, and why 'clusterCut' can not be found.

Here is the data for 'mytable2':

structure(list(clusterCut = c(1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 
3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 
1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 
5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 
3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L
), Var2 = c("Abatino macacapox virus", "Abatino macacapox virus", 
"Abatino macacapox virus", "Abatino macacapox virus", "Abatino macacapox virus", 
"Abatino macacapox virus", "Akhmeta virus", "Akhmeta virus", 
"Akhmeta virus", "Akhmeta virus", "Akhmeta virus", "Akhmeta virus", 
"Alaskapox virus", "Alaskapox virus", "Alaskapox virus", "Alaskapox virus", 
"Alaskapox virus", "Alaskapox virus", "Camelpox virus", "Camelpox virus", 
"Camelpox virus", "Camelpox virus", "Camelpox virus", "Camelpox virus", 
"Cetaceanpox virus", "Cetaceanpox virus", "Cetaceanpox virus", 
"Cetaceanpox virus", "Cetaceanpox virus", "Cetaceanpox virus", 
"Cowpox virus", "Cowpox virus", "Cowpox virus", "Cowpox virus", 
"Cowpox virus", "Cowpox virus", "Ectromelia virus", "Ectromelia virus", 
"Ectromelia virus", "Ectromelia virus", "Ectromelia virus", "Ectromelia virus", 
"Monkeypox virus", "Monkeypox virus", "Monkeypox virus", "Monkeypox virus", 
"Monkeypox virus", "Monkeypox virus", "Raccoonpox virus", "Raccoonpox virus", 
"Raccoonpox virus", "Raccoonpox virus", "Raccoonpox virus", "Raccoonpox virus", 
"Skunkpox virus", "Skunkpox virus", "Skunkpox virus", "Skunkpox virus", 
"Skunkpox virus", "Skunkpox virus", "Vaccinia virus", "Vaccinia virus", 
"Vaccinia virus", "Vaccinia virus", "Vaccinia virus", "Vaccinia virus", 
"Volepox virus", "Volepox virus", "Volepox virus", "Volepox virus", 
"Volepox virus", "Volepox virus"), Freq = c(1, 0, 0, 0, 0, 0, 
1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0.166666666666667, 0, 0, 
0, 0, 0.833333333333333, 0, 0, 1, 0, 0, 0, 0.705882352941177, 
0, 0, 0, 0.294117647058824, 0, 1, 0, 0, 0, 0, 0, 0, 0.945205479452055, 
0.0547945205479452, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 
0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0)), class = "data.frame", row.names = c(NA, 
72L))

Here is the data for 'vtree':

structure(list(edge = structure(c(13L, 14L, 15L, 15L, 16L, 16L, 
14L, 17L, 17L, 18L, 19L, 20L, 21L, 21L, 22L, 22L, 20L, 19L, 23L, 
23L, 18L, 13L, 14L, 15L, 1L, 16L, 2L, 3L, 17L, 4L, 18L, 19L, 
20L, 21L, 5L, 22L, 6L, 7L, 8L, 23L, 9L, 10L, 11L, 12L), dim = c(22L, 
2L)), edge.length = c(0.734311, 0.100672, 0.092785, 0.069175, 
0.07415, 0.049043, 0.076235, 0.07632, 0.030269, 0.025787, 0.004255, 
0.020637, 0.028154, 0.006898, 0.021277, 0.032036, 0.022467, 0.009429, 
0.012776, 0.031136, 0.044858, 0.978308), Nnode = 11L, tip.label = c("027213.1_Raccoonpox", 
"031033.1_Volepox", "031038.1_Skunkpox", "Alaskapox", "003310.1_Monkeypox", 
"006998.1_Vaccinia", "003391.1_Camelpox", "003663.2_Cowpox", 
"055231.1_Abatino", "004105.1_Ectromelia", "055230.1_Akhmeta", 
"Cetaceanpox")), class = "phylo", order = "cladewise")
  • 1
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input that can be used to test and verify possible solutions. Share data with `dput()` so we can copy/paste into R for testing. Also be sure to list all the non-base R package you are using. – MrFlick Jan 09 '23 at 20:13
  • Thank you for that tip! I will edit my post now. – Katie Tseng Jan 09 '23 at 20:41

0 Answers0