YuLab-SMU / ggtree

:christmas_tree:Visualization and annotation of phylogenetic trees
https://yulab-smu.top/contribution-tree-data/
838 stars 173 forks source link

ggtree + gggenes #339

Closed acpguedes closed 4 years ago

acpguedes commented 4 years ago

Hi. Sorry if here Isn't the right place to post this question. I thought the group in Gmail might be too flooded because of the whole code.

I'm trying to do something like the example 13.4 Phylogenetic trees with genome locus structure but it is not working.

I tried something like:

library(gggenes)
library(ggtree)
library(ggtreeExtra)
library(treeio)
library(tidyverse)
library(patchwork)

tree <- structure(list(edge = structure(c(27L, 30L, 30L, 31L, 31L, 33L, 34L, 34L, 36L, 37L, 38L, 43L, 43L, 44L, 44L, 45L, 45L, 47L, 47L, 46L, 48L, 48L, 35L, 49L, 50L, 50L, 27L, 28L, 29L, 29L, 28L, 32L, 33L, 32L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 42L, 41L, 40L, 46L, 39L, 27L, 49L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L ), .Dim = c(49L, 2L), .Dimnames = list(NULL, c("parent", "node" ))), edge.length = c(0.1988391777, 0.104587984, 0.1432040021, 0.3706608904, 0.2516876608, 0.016195795, 0.1233083144, 0.1931835463, 0.8868798252, 1.048012843, 0.9300557898, 0.2813061155, 0.2446558036, 0.2506381045, 0.4005166074, 0.5283676211, 0.8283800695, 0.1849777633, 0.3273584769, 0.2441943354, 0.1305056903, 0.1541044135, 1.0119682788, 0.1464523941, 0.0773354497, 0.1407204251, 0.5409501654, 0.225075936, 0.2667730672, 0.0389981766, 0.0710289638, 0.6366297915, 0.0640540473, 0.1547767482, 0.1331677028, 0.1052379066, 1.470550875, 0.4475668632, 0.2113593463, 0.0654865722, 0.0695866118, 0.1571956639, 0.3048128714, 0.0875384294, 0.4362850343, 0.0635639966, 0.2885315696, 0.1950025877, 0.1816072339), tip.label = c("7", "21", "5", "20", "23", "22", "8", "24", "25", "10", "9", "12", "15", "14", "19", "26", "4", "18", "3", "17", "16", "11", "13", "6", "2", "1"), node.label = c("", "96/100/96", "97/100/96", "100/100/100", "59/87.1/59", "34/79.5/33", "100/100/100", "76/99.7/76", "47/100/49", "40/100/47", "38/46.6/32", "100/100/100", "62/100/69", "48/98.4/58", "40/91.5/46", "37/7.7/39", "98/100/98", "99/100/100", "48/99.8/54", "99/100/99", "70/95.6/76", "99/100/99", "100/100/100", "100/100/100"), Nnode = 24L), class = "phylo")

nbh <- structure(list(label = c("NP_951939.1", "NP_951939.1", "NP_951939.1", "NP_951939.1", "NP_951939.1", "NP_951939.1", "NP_951939.1", "NP_951939.1", "NP_951939.1", "NP_951939.1", "NP_951939.1", "NP_951939.1", "NP_951939.1", "WP_002809840.1", "WP_002809840.1", "WP_002809840.1", "WP_002809840.1", "WP_002809840.1", "WP_002809840.1", "WP_002809840.1", "WP_002809840.1", "WP_002809840.1", "WP_002809840.1", "WP_002809840.1", "WP_002809840.1", "WP_002809840.1", "WP_002809840.1", "WP_002809840.1", "WP_002809840.1", "WP_004511723.1", "WP_004511723.1", "WP_004511723.1", "WP_004511723.1", "WP_004511723.1", "WP_004511723.1", "WP_004511723.1", "WP_004511723.1", "WP_004511723.1", "WP_004511723.1", "WP_004511723.1", "WP_004511723.1", "WP_004511723.1", "WP_011735271.1", "WP_011735271.1", "WP_011735271.1", "WP_011735271.1", "WP_011735271.1", "WP_011735271.1", "WP_011735271.1", "WP_011735271.1", "WP_011938858.1", "WP_011938858.1", "WP_011938858.1", "WP_011938858.1", "WP_049759709.1", "WP_049759709.1", "WP_049759709.1", "WP_012468660.1", "WP_012468660.1", "WP_012468660.1", "WP_012468660.1", "WP_049759709.1", "WP_049759709.1", "WP_012468660.1", "WP_012468660.1", "WP_012468660.1", "WP_012468660.1", "WP_012468660.1", "WP_012468660.1", "WP_049759709.1", "WP_049759709.1", "WP_049759709.1", "WP_049759709.1", "WP_012530820.1", "WP_012530820.1", "WP_012530820.1", "WP_012530820.1", "WP_012530820.1", "WP_012530820.1", "WP_012648277.1", "WP_012648277.1", "WP_012648277.1", "WP_012648277.1", "WP_013032448.1", "WP_013032448.1", "WP_013032448.1", "WP_013032448.1", "WP_013032448.1", "WP_013032448.1", "WP_013032448.1", "WP_013032448.1", "WP_013032448.1", "WP_013032448.1", "WP_013032448.1", "WP_013032448.1", "WP_013032448.1", "WP_013032448.1", "WP_013032448.1", "WP_013032448.1", "WP_013220193.1", "WP_013220193.1", "WP_013220193.1", "WP_013220193.1", "WP_013220193.1", "WP_013220193.1", "WP_013220193.1", "WP_013220193.1", "WP_013220193.1", "WP_013220193.1", "WP_013220193.1", "WP_013220193.1", "WP_013220193.1", "WP_013220193.1", "WP_013220193.1", "WP_013220193.1", "WP_013220193.1", "WP_015719348.1", "WP_015719348.1", "WP_015720100.1", "WP_015720100.1", "WP_015720100.1", "WP_015720100.1", "WP_015720100.1", "WP_015719348.1", "WP_015719348.1", "WP_015720100.1", "WP_013817816.1", "WP_013817816.1", "WP_013817816.1", "WP_013817816.1", "WP_013817816.1", "WP_013817816.1", "WP_013817816.1", "WP_013817816.1", "WP_013817816.1", "WP_013817816.1", "WP_013817816.1", "WP_013817816.1", "WP_013817816.1", "WP_013817816.1", "WP_013817816.1", "WP_013817816.1", "WP_013817816.1", "WP_013817816.1", "WP_013817816.1", "WP_015404607.1", "WP_015404607.1", "WP_015404607.1", "WP_015404607.1", "WP_015404607.1", "WP_015404607.1", "WP_096527766.1", "WP_096527766.1", "WP_096527766.1", "WP_096527766.1", "WP_096527766.1", "WP_096527766.1", "WP_096527766.1", "WP_096527766.1", "WP_096527766.1", "WP_096527766.1", "WP_096527766.1", "WP_096527766.1", "WP_096527766.1", "WP_096527766.1", "WP_096527766.1", "WP_096527766.1", "WP_039743299.1", "WP_039743299.1", "WP_039743299.1", "WP_039743299.1", "WP_039743299.1", "WP_039743299.1", "WP_039743299.1", "WP_039743299.1", "WP_039743299.1", "WP_039743299.1", "WP_039743299.1", "WP_081992788.1", "WP_081992788.1", "WP_081992788.1", "WP_081992788.1", "WP_081992788.1", "WP_081992788.1", "WP_081992788.1", "WP_081992788.1", "WP_081992788.1", "WP_081992788.1", "WP_081992788.1", "WP_081992788.1", "WP_081992788.1", "WP_081992788.1", "WP_081992788.1", "WP_081992788.1", "WP_082219776.1", "WP_082219776.1", "WP_082219776.1", "WP_082219776.1", "WP_082219776.1", "WP_082219776.1", "WP_082219776.1", "WP_082219776.1", "WP_082219776.1", "WP_082219776.1", "WP_082219776.1", "WP_082219776.1", "WP_082881023.1", "WP_082881023.1", "WP_082881023.1", "WP_082881023.1", "WP_082881023.1", "WP_082881023.1", "WP_082881023.1", "WP_082881023.1", "WP_082881023.1", "WP_082881023.1", "WP_082881023.1", "WP_082881023.1", "WP_082881023.1", "WP_082881023.1", "WP_036273245.1", "WP_036273245.1", "WP_036273245.1", "WP_036273245.1", "WP_036273245.1", "WP_036273245.1", "WP_036273245.1", "WP_036273245.1", "WP_036273245.1", "WP_036273245.1", "WP_036273245.1", "WP_036273245.1", "WP_036273245.1", "WP_036273245.1", "WP_036273245.1", "WP_036273245.1", "WP_036273245.1", "WP_036273245.1", "WP_068803447.1", "WP_068803447.1", "WP_068803447.1", "WP_068803447.1", "WP_068803447.1", "WP_068803447.1", "WP_068803447.1", "WP_068803447.1", "WP_068803447.1", "WP_068803447.1", "WP_068803447.1", "WP_068803447.1", "WP_086931739.1", "WP_086931739.1", "WP_086931739.1", "WP_086931739.1", "WP_086931739.1", "WP_086931739.1", "WP_099879450.1", "WP_099879450.1", "WP_099879450.1", "WP_099879450.1", "WP_099879450.1", "WP_099879450.1", "WP_108603477.1", "WP_108603477.1", "WP_108603477.1", "WP_108603477.1", "WP_108603477.1", "WP_108603477.1", "WP_108603477.1", "WP_108603477.1", "WP_108603477.1", "WP_107142342.1", "WP_107142342.1", "WP_107142342.1", "WP_107142342.1", "WP_107142342.1", "WP_107142342.1", "WP_107142342.1", "WP_107142342.1", "WP_107142342.1", "WP_107142342.1", "WP_107142342.1", "WP_107142342.1", "WP_107142342.1", "WP_107142342.1", "WP_107142342.1", "WP_107142342.1"), block_id = c("17", "17", "17", "17", "17", "17", "17", "17", "17", "17", "17", "17", "17", "21", "21", "21", "21", "21", "21", "21", "21", "21", "21", "21", "21", "21", "21", "21", "21", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "19", "19", "19", "19", "19", "19", "19", "19", "15", "15", "15", "15", "26", "26", "26", "14", "14", "14", "14", "26", "26", "14", "14", "14", "14", "14", "14", "26", "26", "26", "26", "16", "16", "16", "16", "16", "16", "12", "12", "12", "12", "23", "23", "23", "23", "23", "23", "23", "23", "23", "23", "23", "23", "23", "23", "23", "23", "5", "5", "5", "5", "5", "5", "5", "5", "5", "5", "5", "5", "5", "5", "5", "5", "5", "4", "4", "11", "11", "11", "11", "11", "4", "4", "11", "22", "22", "22", "22", "22", "22", "22", "22", "22", "22", "22", "22", "22", "22", "22", "22", "22", "22", "22", "9", "9", "9", "9", "9", "9", "20", "20", "20", "20", "20", "20", "20", "20", "20", "20", "20", "20", "20", "20", "20", "20", "18", "18", "18", "18", "18", "18", "18", "18", "18", "18", "18", "7", "7", "7", "7", "7", "7", "7", "7", "7", "7", "7", "7", "7", "7", "7", "7", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "24", "24", "24", "24", "24", "24", "24", "24", "24", "24", "24", "24", "24", "24", "8", "8", "8", "8", "8", "8", "8", "8", "8", "8", "8", "8", "8", "8", "8", "8", "8", "8", "25", "25", "25", "25", "25", "25", "25", "25", "25", "25", "25", "25", "10", "10", "10", "10", "10", "10", "6", "6", "6", "6", "6", "6", "13", "13", "13", "13", "13", "13", "13", "13", "13", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1"), pid = c("NP_951940.1", "NP_951940.1", "NP_951940.1", "query", "query", "NP_951938.1", "NP_951938.1", "NP_951938.1", "NP_951938.1", "NP_951938.1", "NP_951937.1", "NP_951937.1", "NP_951937.1", "WP_011330608.1", "WP_011330609.1", "WP_011330609.1", "WP_011330609.1", "query", "query", "WP_011330611.1", "WP_011330611.1", "WP_011330611.1", "WP_011330611.1", "WP_011330611.1", "WP_011330611.1", "WP_011330611.1", "WP_011330611.1", "WP_011330611.1", "WP_011330611.1", "WP_011366092.1", "WP_011366092.1", "WP_011366092.1", "query", "query", "WP_004511722.1", "WP_004511722.1", "WP_004511722.1", "WP_004511722.1", "WP_004511722.1", "WP_004511721.1", "WP_004511721.1", "WP_004511721.1", "WP_011735270.1", "WP_011735270.1", "query", "query", "WP_049759664.1", "WP_049759664.1", "WP_049759664.1", "WP_049759666.1", "WP_011938857.1", "WP_011938857.1", "query", "query", "WP_012470932.1", "WP_012470932.1", "WP_012470932.1", "WP_083768661.1", "WP_083768661.1", "query", "query", "query", "query", "WP_012468661.1", "WP_012468661.1", "WP_012468661.1", "WP_012468661.1", "WP_012468661.1", "WP_012468661.1", "WP_012470934.1", "WP_012470934.1", "WP_012470934.1", "WP_012470934.1", "WP_012530821.1", "WP_012530821.1", "WP_012530821.1", "query", "query", NA, "WP_012648278.1", "WP_012648278.1", "query", "query", "WP_013032446.1", "WP_013032446.1", "WP_013032446.1", "WP_013032447.1", "query", "WP_013032449.1", "WP_013032449.1", "WP_013032449.1", "WP_013032449.1", "WP_013032449.1", "WP_013032449.1", "WP_013032449.1", "WP_013032449.1", "WP_013032449.1", "WP_013032449.1", "WP_013032449.1", "WP_013220191.1", "WP_013220191.1", "WP_013220192.1", "WP_013220192.1", "WP_013220192.1", "query", "query", "WP_013220194.1", "WP_013220194.1", "WP_013220194.1", "WP_013220194.1", "WP_013220194.1", "WP_013220194.1", "WP_013220194.1", "WP_013220194.1", "WP_013220194.1", "WP_013220194.1", "WP_015719349.1", "WP_015719349.1", "WP_015720099.1", "WP_015720099.1", "WP_015720099.1", "query", "query", "query", "query", NA, "WP_013817818.1", "WP_013817817.1", "WP_013817817.1", "WP_013817817.1", "query", "query", "WP_013817815.1", "WP_013817815.1", "WP_013817815.1", "WP_013817815.1", "WP_013817815.1", "WP_013817815.1", "WP_013817815.1", "WP_013817815.1", "WP_013817815.1", "WP_013817815.1", "WP_013817815.1", "WP_013817814.1", "WP_013817814.1", "query", "query", "WP_015404606.1", "WP_015404606.1", "WP_015404606.1", "WP_015404606.1", "WP_096526868.1", "WP_096527765.1", "WP_096527765.1", "WP_096527765.1", "query", "WP_096526869.1", "WP_096526869.1", "WP_096526869.1", "WP_096526869.1", "WP_096526869.1", "WP_096526869.1", "WP_096526869.1", "WP_096526869.1", "WP_096526869.1", "WP_096526869.1", "WP_096526869.1", "WP_039743297.1", "WP_039743297.1", "WP_039743297.1", "query", "query", "WP_052263412.1", "WP_052263412.1", "WP_052263412.1", "WP_052263412.1", "WP_052263412.1", "WP_084201425.1", "WP_038490313.1", "WP_038490310.1", "WP_038490310.1", "WP_038490310.1", "query", "WP_052135224.1", "WP_052135224.1", "WP_052135224.1", "WP_052135224.1", "WP_052135224.1", "WP_052135224.1", "WP_052135224.1", "WP_052135224.1", "WP_052135224.1", "WP_052135224.1", "WP_052135224.1", "WP_082219325.1", "query", "WP_050407626.1", "WP_050407626.1", "WP_050407626.1", "WP_050407626.1", "WP_050407626.1", "WP_050407626.1", "WP_050407626.1", "WP_050407626.1", "WP_050407626.1", "WP_050407626.1", "WP_054763479.1", "query", "query", "WP_064022982.1", "WP_064022982.1", "WP_064022982.1", "WP_064022982.1", "WP_064022982.1", "WP_064022982.1", "WP_064022982.1", "WP_064022982.1", "WP_064022982.1", "WP_064022982.1", "WP_064022982.1", "WP_036273249.1", "WP_036273249.1", "WP_036273249.1", "WP_036273247.1", "WP_036273247.1", "WP_036273247.1", "query", "query", "WP_062329224.1", "WP_062329224.1", "WP_062329224.1", "WP_062329224.1", "WP_062329224.1", "WP_062329224.1", "WP_062329224.1", "WP_062329224.1", "WP_062329224.1", "WP_062329224.1", NA, "query", "WP_068803449.1", "WP_068803449.1", "WP_068803449.1", "WP_068803449.1", "WP_068803449.1", "WP_068803449.1", "WP_068803449.1", "WP_068803449.1", "WP_068803449.1", "WP_068803449.1", "WP_086931737.1", "WP_086931738.1", "WP_086931738.1", "WP_086931738.1", "query", "query", "WP_099879448.1", "WP_099879448.1", "WP_099882743.1", "WP_099882743.1", "query", "query", "WP_108603478.1", "WP_108603478.1", "WP_108605061.1", "query", "query", "WP_108603476.1", "WP_108603476.1", "WP_108603476.1", "WP_108603476.1", "query", "query", "WP_107142343.1", "WP_107142343.1", "WP_107142343.1", "WP_107142343.1", "WP_107142343.1", "WP_107142343.1", "WP_107142343.1", "WP_107142343.1", "WP_107142343.1", "WP_107142343.1", "WP_107142343.1", "WP_107142344.1", "WP_107142344.1", "WP_107142344.1"), query = c(FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE ), start = c(-1904, -1904, -1904, 0, 0, 876, 876, 876, 876, 876, 2470, 2470, 2470, -3120, -2284, -2284, -2284, 0, 0, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, -1973, -1973, -1973, 0, 0, 870, 870, 870, 870, 870, 2642, 2642, 2642, -1877, -1877, 0, 0, 1128, 1128, 1128, 3136, -1844, -1844, 0, 0, -1826, -1826, -1826, -1802, -1802, 0, 0, 0, 0, 854, 854, 854, 854, 854, 854, 881, 881, 881, 881, -1835, -1835, -1835, 0, 0, 848, -1820, -1820, 0, 0, -3074, -3074, -3074, -918, 0, 894, 894, 894, 894, 894, 894, 894, 894, 894, 894, 894, -3119, -3119, -2280, -2280, -2280, 0, 0, 966, 966, 966, 966, 966, 966, 966, 966, 966, 966, -1946, -1946, -1808, -1808, -1808, 0, 0, 0, 0, 850, -3138, -2279, -2279, -2279, 0, 0, 954, 954, 954, 954, 954, 954, 954, 954, 954, 954, 954, 5566, 5566, 0, 0, 908, 908, 908, 908, -3224, -2382, -2382, -2382, 0, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, -1907, -1907, -1907, 0, 0, 905, 905, 905, 905, 905, 2524, -3172, -2284, -2284, -2284, 0, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, -2644, 0, 1080, 1080, 1080, 1080, 1080, 1080, 1080, 1080, 1080, 1080, -3100, 0, 0, 971, 971, 971, 971, 971, 971, 971, 971, 971, 971, 971, -4135, -4135, -4135, -2202, -2202, -2202, 0, 0, 950, 950, 950, 950, 950, 950, 950, 950, 950, 950, -1378, 0, 852, 852, 852, 852, 852, 852, 852, 852, 852, 852, -3119, -2113, -2113, -2113, 0, 0, -2112, -2112, -1130, -1130, 0, 0, -2090, -2090, -931, 0, 0, 881, 881, 881, 881, 0, 0, 1164, 1164, 1164, 1164, 1164, 1164, 1164, 1164, 1164, 1164, 1164, 5384, 5384, 5384), end = c(-21, -21, -21, 872, 872, 2450, 2450, 2450, 2450, 2450, 4485, 4485, 4485, -2320, -152, -152, -152, 956, 956, 5465, 5465, 5465, 5465, 5465, 5465, 5465, 5465, 5465, 5465, -21, -21, -21, 863, 863, 2441, 2441, 2441, 2441, 2441, 4657, 4657, 4657, 3, 3, 893, 893, 3143, 3143, 3143, 3537, 12, 12, 896, 896, 3, 3, 3, 0, 0, 857, 857, 884, 884, 2857, 2857, 2857, 2857, 2857, 2857, 2467, 2467, 2467, 2467, 12, 12, 12, 851, 851, 2499, 3, 3, 854, 854, -948, -948, -948, -199, 884, 5393, 5393, 5393, 5393, 5393, 5393, 5393, 5393, 5393, 5393, 5393, -2319, -2319, -148, -148, -148, 956, 956, 5468, 5468, 5468, 5468, 5468, 5468, 5468, 5468, 5468, 5468, 0, 0, 12, 12, 12, 848, 848, 854, 854, 2492, -2314, -54, -54, -54, 947, 947, 5399, 5399, 5399, 5399, 5399, 5399, 5399, 5399, 5399, 5399, 5399, 6423, 6423, 905, 905, 2713, 2713, 2713, 2713, -2421, -265, -265, -265, 878, 5399, 5399, 5399, 5399, 5399, 5399, 5399, 5399, 5399, 5399, 5399, -21, -21, -21, 872, 872, 2533, 2533, 2533, 2533, 2533, 2925, -2366, -176, -176, -176, 896, 5487, 5487, 5487, 5487, 5487, 5487, 5487, 5487, 5487, 5487, 5487, -1439, 1037, 5618, 5618, 5618, 5618, 5618, 5618, 5618, 5618, 5618, 5618, -2429, 965, 965, 5410, 5410, 5410, 5410,  5410, 5410, 5410, 5410, 5410, 5410, 5410, -2411, -2411, -2411, -52, -52, -52, 944, 944, 5371, 5371, 5371, 5371, 5371, 5371, 5371, 5371, 5371, 5371, -626, 824, 4946, 4946, 4946, 4946, 4946, 4946, 4946, 4946, 4946, 4946, -2256, 10, 10, 10, 923, 923, -1315, -1315, -132, -132, 1121, 1121, -1014, -1014, -533, 878, 878, 2434, 2434, 2434, 2434, 1151, 1151, 5231, 5231, 5231, 5231, 5231, 5231, 5231, 5231, 5231, 5231, 5231, 7495, 7495, 7495), strand = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), domain = c("SP", "Plug", "TonB_dep_Rec", "SP", "ABC_sub_bind", "TM", "TM", "HAMP", "HisKA", "HATPase_c", "Molybdop_Fe4S4", "Molybdopterin", "Molydop_binding", "Citrate_synt", "SP", "Plug", "TonB_dep_Rec", "SP", "ABC_sub_bind", "SP", "TM", "HisKA", "HATPase_c", "Response_reg", "Response_reg", "Hpt", "Response_reg", "GGDEF", "EAL", "SP", "Plug", "TonB_dep_Rec", "SP", "ABC_sub_bind", "TM", "TM", "HAMP", "HisKA", "HATPase_c", "Molybdop_Fe4S4", "Molybdopterin", "Molydop_binding", "SP", "Plug", "SP", "ABC_sub_bind", "TM", "TM", "HATPase_c", "Response_reg", "SP", "Plug", "SP", "ABC_sub_bind", "SP", "Plug", "TonB_dep_Rec", "Plug", "TonB_dep_Rec", "SP", "ABC_sub_bind", "SP", "ABC_sub_bind", "TM", "TM", "HAMP", "HisKA", "HATPase_c", "Response_reg", "TM", "TM", "HAMP", "HATPase_c", "SP", "Plug", "TonB_dep_Rec", "SP", "ABC_sub_bind", NA, "SP", "Plug", "SP", "ABC_sub_bind", "SP", "Plug", "TonB_dep_Rec", "adh_short_C2", "ABC_sub_bind", "SP", "DUF2222", "TM", "HisKA", "HATPase_c", "Response_reg", "Response_reg", "Hpt", "Response_reg", "GGDEF", "EAL", "TM", "TM", "SP", "Plug", "TonB_dep_Rec", "SP", "ABC_sub_bind", "SP", "TM", "HisKA", "HATPase_c", "Response_reg", "Response_reg", "Hpt", "Response_reg", "GGDEF", "EAL", "SP", "Plug", "SP", "Plug", "TonB_dep_Rec", "SP", "ABC_sub_bind", "SP", "ABC_sub_bind", NA, NA, "SP", "Plug", "TonB_dep_Rec", "SP", "ABC_sub_bind", "TM", "DUF2222", "TM", "HAMP", "HisKA", "HATPase_c", "Response_reg", "Hpt", "Response_reg", "GGDEF", "EAL", "SP", "PBP_like_2", "SP", "ABC_sub_bind", "TM", "TM", "HisKA", "HATPase_c", NA, "SP", "Plug", "TonB_dep_Rec", "ABC_sub_bind", "TM", "DUF2222", "TM", "HisKA", "HATPase_c", "Response_reg", "Response_reg", "Hpt", "Response_reg", "GGDEF", "EAL", "SP", "Plug", "TonB_dep_Rec", "SP", "ABC_sub_bind", "TM", "TM", "HAMP", "HisKA", "HATPase_c", "Response_reg", NA, "SP", "Plug", "TonB_dep_Rec", "ABC_sub_bind", "TM", "DUF2222", "TM", "HisKA", "HATPase_c", "Response_reg", "Response_reg", "Hpt", "Response_reg", "GGDEF", "EAL", "Aminotran_5", "ABC_sub_bind", "TM", "DUF2222", "TM", "HisKA", "HATPase_c", "Response_reg", "Hpt", "Response_reg", "GGDEF", "EAL", "Nitroreductase", "SP", "ABC_sub_bind", "TM", "DUF2222", "TM", "HAMP", "HisKA", "HATPase_c", "Response_reg", "Hpt", "Response_reg", "GGDEF", "EAL", "PP2C_2", "Pkinase", "TM", "SP", "Plug", "TonB_dep_Rec", "SP", "ABC_sub_bind", "TM", "TM", "HAMP", "HisKA", "HATPase_c", "Response_reg", "Hpt", "Response_reg", "GGDEF", "EAL", NA, "ABC_sub_bind", "TM", "TM", "HAMP", "HisKA", "HATPase_c", "Response_reg", "Hpt", "Response_reg", "GGDEF", "EAL", NA, "SP", "Plug", "TonB_dep_Rec", "SP", "ABC_sub_bind", "Lactamase_B", "HAGH_C", "SP", "ABC_sub_bind", "SP", "ABC_sub_bind", "TM", "Peptidase_S49", "RF-1", "SP", "ABC_sub_bind", "TM", "TM", "HisKA", "HATPase_c", "SP", "ABC_sub_bind", "TM", "DUF2222", "TM", "HAMP", "HisKA", "HATPase_c", "Response_reg", "Hpt", "Response_reg", "GGDEF", "EAL", "SP", "Plug", "TonB_dep_Rec" ), from = c(-1901, -1682, -1331, 3, 171, 945, 1452, 1518, 1779, 2106, 2479, 2650, 4129, -3069, -2281, -2125, -1687, 3, 159, 969, 1524, 1782, 2118, 2526, 2958, 3429, 3744, 4128, 4653, -1970, -1736, -1382, 3, 171, 957, 1422, 1485, 1749, 2076, 2651, 2825, 4304, -1874, -1706, 3, 168, 1188, 1632, 2706, 3139, -1841, -1685, 3, 171, -1823, -1673, -1337, -1706, -1241, 3, 96, 3, 186, 986, 1430, 1493, 1724, 2060, 2486, 935, 1385, 1448, 2120, -1832, -1652, -1280, 3, 72, NA, -1817, -1664, 3, 72, -3071, -2918, -2414, -894, 90, 897, 1020, 1437, 1710, 2046, 2454, 2886, 3366, 3675, 4059, 4584, -2522, -2453, -2277, -2121, -1683, 3, 333, 969, 1524, 1782, 2118, 2529, 2961, 3432, 3747, 4131, 4656, -1943, -1718, -1805, -1640, -1295, 3, 201, 3, 174, NA, NA, -2276, -2054, -1493, 3, 138, 1014, 1077, 1494, 1557, 1767, 2103, 2937, 3405, 3717, 4101, 4626, 5569, 5659, 3, 72, 956, 1475, 1871, 2309, NA, -2379, -2232, -1686, 264, 948, 1017, 1443, 1707, 2043, 2454, 2868, 3369, 3687, 4071, 4596, -1904, -1679, -1235, 3, 156, 992, 1508, 1568, 1829, 2171, 2548, NA, -2281, -2131, -1555, 45, 1045, 1117, 1525, 1810, 2146, 2548, 2977, 3463, 3778, 4162, 4687, -2509, 249, 1125, 1200, 1614, 1887, 2223, 3075, 3630, 3939, 4323, 4848, -3064, 3, 195, 1031, 1097, 1511, 1574, 1784, 2120, 2948, 3419, 3737, 4121, 4646, -4102, -3319, -2473, -2199, -2046, -1473, 3, 162, 992, 1493, 1556, 1766, 2102, 2930, 3392, 3704, 4088, 4613, NA, 114, 912, 1404, 1467, 1677, 2013, 2436, 2913, 3237, 3621, 4143, NA, -2110, -1933, -1525, 3, 135, -2058, -1578, -1127, -671, 3, 321, -2048, -1586, -922, 3, 291, 941, 1424, 1751, 2093, 3, 528, 1224, 1305, 1713, 1776, 1986, 2322, 2751, 3219, 3534, 3918, 4443, 5387, 5546, 5882), to = c(-1769, -1364, -26, 63, 861, 1008, 1521, 1671, 1983, 2442, 2641, 3871, 4462, -2385, -2215, -1792, -157, 96, 930, 1074, 1593, 1977, 2466, 2874, 3297, 3696, 4080, 4599, 5361, -1823, -1424, -26, 63, 861, 1017, 1491, 1641, 1947, 2409, 2810, 4046, 4634, -1787, -1388, 63, 870, 1245, 1695, 3060, 3478, -1763, -1361, 72, 876, -1748, -1355, -2, -1388, -5, 63, 855, 69, 867, 1049, 1499, 1649, 1919, 2408, 2828, 995, 1451, 1601, 2450, -1730, -1334, 7, 63, 834, NA, -1745, -1346, 63, 852, -3011, -2588, -953, -204, 864, 1002, 1428, 1503, 1905, 2394, 2802, 3225, 3633, 4011, 4530, 5292, -2471, -2396, -2211, -1788, -153, 96, 933, 1074, 1593, 1977, 2466, 2877, 3300, 3702, 4083, 4602, 5364, -1796, -1397, -1718, -1322, 7, 63, 792, 66, 852, NA, NA, -2147, -1721, -59, 72, 924, 1089, 1497, 1557, 1713, 1962, 2451, 3276, 3669, 4053, 4569, 5334, 5626, 6376, 63, 897, 1022, 1544, 2186, 2633, NA, -2319, -1899, -270, 849, 1008, 1425, 1500, 1902, 2391, 2775, 3210, 3633, 4023, 4542, 5304, -1769, -1361, -26, 63, 864, 1052, 1574, 1721, 2033, 2489, 2911, NA, -2215, -1798, -181, 876, 1099, 1525, 1606, 2005, 2494, 2884, 3319, 3718, 4114, 4630, 5392, -1465, 1014, 1179, 1599, 1680, 2082, 2574, 3417, 3870, 4275, 4791, 5556, -2497, 93, 948, 1106, 1511, 1580, 1730, 1979, 2468, 3287, 3698, 4073, 4589, 5354, -3478, -2548, -2419, -2139, -1713, -57, 75, 921, 1061, 1559, 1712, 1961, 2450, 3269, 3647, 4040, 4556, 5321, NA, 813, 984, 1473, 1623, 1872, 2361, 2775, 3171, 3573, 4086, 4851, NA, -2029, -1600, 5, 60, 903, -1581, -1317, -1019, -164, 117, 1095, -1991, -1133, -544, 42, 861, 1004, 1481, 1955, 2426, 81, 1122, 1284, 1704, 1779, 1932, 2181, 2667, 3093, 3480, 3870, 4386, 5151, 5462, 5879, 7490)), row.names = c(NA, -287L), class = c("tbl_df", "tbl", "data.frame"))

tree_plot <- tree %>% 
  ggplot() +
  geom_tree() +
  geom_tiplab(aes(label=label))  

nbh_plot <- ggplot(
  (nbh %>% select(label, nucleotide,block_id,pid,start,end,strand) %>% distinct()),
  aes(xmin = start, xmax = end, y = block_id, forward = strand) # as_factor(block_id)
) +
  geom_gene_arrow() +
  geom_subgene_arrow(
    data = myset,
    aes(xmin = start, xmax= end, xsubmin = from, xsubmax = to, fill = domain, y = block_id) # y = as_factor(block_id)
  ) +
  geom_subgene_label(
    data = myset,
    aes(xmin = start, xmax= end, xsubmin = from, xsubmax = to, label = domain, y = (block_id)),
    min.size = 0
  ) + 
  #scale_fill_brewer(palette = "Set3") +
  theme_genes() %+replace% 
  theme(panel.grid.major.y = element_line(colour = NULL)) + # , linetype = "dotted")) +
  #theme_classic() +
  theme(
    axis.title.x=element_blank(),
    #axis.text.x=element_blank(),
    axis.ticks.x=element_blank(), 
    #axis.line.x = element_blank(),
    axis.title.y=element_blank(),
    #axis.text.y=element_blank(),
    axis.ticks.y=element_blank(), 
    axis.line.y = element_blank()
  ) 

(tree_plot + theme_tree())  + nbh_plot 
# OBS: without `theme_tree()` it does not work

This works but does not align them. image

I also tried another method which lacks the sub-motifs (domains) showed in nbh_plot

tree_plot +
 geom_fruit(
    data=(
      nbh %>% 
        select(molecule = block_id, label, nucleotide,pid,start,end,strand, query) %>% 
        distinct()
    ),
    mapping = aes(xmin = start, xmax = end, y = molecule, forward = strand),
    geom=geom_gene_arrow, 
    on = "query", panel = "Alignemnt"
  )  

# Error in which(flag) : argument to 'which' is not logical

Another variation with geom_facet which also lacks the domains and the figure not shows the alignment

tre_plot +
 geom_facet(
    data=(
      myset %>% 
        select(molecule = block_id, label, nucleotide,pid,start,end,strand, query) %>% 
        distinct()
    ),
    mapping=aes(xmin = start, xmax = end, fill=query ),
    geom=geom_motif, 
    on = "query", panel = "Alignemnt"
  )

image

GuangchuangYu commented 4 years ago

pls follow: http://yulab-smu.top/treedata-book/chapter13.html#genome-locus.

GuangchuangYu commented 4 years ago

gggenes and ggtree are not fully compatible. This is the reason why we provide geom_motif() which is a wrapper for gggenes.

GuangchuangYu commented 4 years ago

If you want to align them using cowplot or patchwork, you need to adjust the order yourself and make sure that they are properly align, see also https://github.com/YuLab-SMU/ggtree/issues/313.

acpguedes commented 4 years ago

I found a way which might be useful even if it is not the best one.

Fist extract an ordered list of the leaves:

leaf_order <- tre_plot$data %>% 
  filter(isTip) %>%  
  arrange(y) %>% 
  pull(block_id)

And, on the plot, adjust the y axis scale:

nbh_plot + 
    scale_y_discrete(limits=leaf_order)

Remember convert numeric type in factor.

Finally combine them:: tree_plo + nbh_plot

GuangchuangYu commented 4 years ago

there is a function get_taxa_name in ggtree that can extract taxa order displayed on the ggtree() plot.

If you want to do it in this way, I recommend you using aplot package (examples can be found https://yulab-smu.top/treedata-book/chapter7.html#composite_plot).