使用ggtree的facet_plot函数时出现'clusterCut未找到'错误
问题:ggtree绘制树+堆叠柱状图时提示找不到
clusterCut列 问题详情
我尝试绘制左侧为系统发育树、右侧为水平堆叠柱状图的组合图,使用的代码如下:
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)
运行代码时出现以下错误:
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]], ...)
我无法理解错误原因,不清楚为什么会提示找不到clusterCut。以下是mytable2和vtree的数据结构:
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))
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")
内容的提问来源于stack exchange,提问作者Katie Tseng
相关产品推荐
相关产品推荐

