Main manuscript
Figures
Figure 1 - Phylogenetic tree with traits
# Prepare data sets ###################
Reflectance <- read.csv(here::here("Data/FromCode/Reflectance_PData.csv"))[-1]
RPDataAgg <- read.csv(here::here("Data/FromCode/PolarzElytraRefl.csv"))[-1]
RPDAgg1 <-
RPDataAgg %>%
dplyr::select(-ind, -spp) %>%
dplyr::select(phylogeny_name, everything()) %>%
dplyr::group_by(phylogeny_name) %>% # group
dplyr::summarise(across(everything(), list(mean))) %>%
select(1,9) %>%
arrange(phylogeny_name)
Cons1agg <- read.csv(here::here("Data/FromCode/ConsolidatedReflectivitySpp.csv"))[-1] %>%
arrange(phylogeny_name) %>%
mutate (Pol = RPDAgg1$ElytrPol_1)
# Convert to a data frame for the comparative.data function
Cons1agg <- as.data.frame(Cons1agg)
head(Cons1agg)
phylogeny_name | TOT | VIS | NIR | Res | size | FRS | FRS2 | Pol |
---|---|---|---|---|---|---|---|---|
Anomala_antigua | 17.2 | 4.55 | 28.3 | -3.46 | 1.77 | -6.92 | -1.29 | 0.161 |
Anoplognathus_abnormis | 27.3 | 16.5 | 36.6 | -6.87 | 1.58 | -11.2 | -1.85 | 0.0643 |
Anoplognathus_aeneus | 22.1 | 10.4 | 32.3 | -5.22 | 3.11 | -9.12 | -3.07 | 0.112 |
Anoplognathus_aureus | 44.9 | 34.3 | 54.2 | -6.82 | 1.71 | -12.5 | -1.47 | 0.206 |
Anoplognathus_boisduvalii | 31.1 | 17.3 | 43.2 | -1.06 | 2.61 | -5.48 | -1.23 | 0.0885 |
Anoplognathus_brevicollis | 27.4 | 12.9 | 40.1 | 0.236 | 2.51 | -3.85 | 0.216 | 0.0871 |
# Modify to make it compatible with tree tips
ConsAgg<- as.data.frame(Cons1agg) # create new data frame
rownames(ConsAgg) <- ConsAgg[, 1] # make species the row names
ConsAgg <- ConsAgg[, 2:length(ConsAgg)] # eliminate spp name (redundant)
# Separate data frames
TOTdf <- ConsAgg %>% dplyr::select(TOT)
VISdf <- ConsAgg %>% dplyr::select(VIS)
Resdf <- ConsAgg %>% dplyr::select(Res)
Poldf <- ConsAgg %>% dplyr::select(Pol)
# Combine with phylogeny ###################
# Phylogeny
trees <- ape::read.tree(here::here("Data/XMAS_mat2b_bst2ef_set23nn2_pinct.nwk"))
# read the tree
MCCtree.raw <-
ape::read.nexus(here::here("Data/xmas_mat2b_bst2ef_set23nn2_pinct_med.tre"))
# Prune extra spp in the tree, not contain in the test sample
species.MCC <- as.data.frame(unique(Cons1agg$phylogeny_name))
# Convert to "row names" (required for following steps)
row.names(species.MCC) <- species.MCC[, 1]
# Make sure the names in data set and tree match
temp.MCC <- name.check(MCCtree.raw, species.MCC)
# This step would be neccesary if the tips had been different.
# MCCtree <- drop.tip(MCCtree.raw, temp.MCC$tree_not_data)
# Not used in our case.
# Instead, changed the name
MCCtree <- MCCtree.raw
# This is to control the length of the tips:
MCCtree$edge.length <- MCCtree$edge.length * 0.1 # Run only once!
# Add traits to the tree ######################
# create a MCC tree without tip names for the plot
tree_only <- ggtree(MCCtree, layout = "rectangular")
# create heat map columns
# Note: log transforms increase contrast for visualization purposes
# Add TOTAL reflectivity
p0 <- gheatmap(tree_only, (TOTdf),
width = 0.04, low = "gray90", high = "#ffc100",
font.size = 2.2,
colnames_position = "bottom", colnames_angle = 90,
colnames_offset_x = 0, colnames_offset_y = -0.5,
legend_title = "TOT"
)
p1.scale <- p0 + new_scale_fill() # add new scale for second variable
# Add VIS
p1 <- gheatmap(p1.scale, (VISdf),
offset = 0.12, # to avoid overlapping with p1
width = 0.04, low = "gray90", high = "#fe6100",
font.size = 2.2,
colnames_position = "bottom", colnames_angle = 90,
colnames_offset_x = 0, colnames_offset_y = -0.5,
legend_title = "VIS"
)
p2.scale <- p1 + new_scale_fill() # add new scale for third variable
# Add NIR
p2 <- gheatmap(p2.scale, (Resdf),
offset = 0.24, # to avoid overlapping with p1
width = 0.04, low = "gray90", high = "#ff2c85",
font.size = 2.2,
colnames_position = "bottom", colnames_angle = 90,
colnames_offset_x = 0, colnames_offset_y = -0.5,
legend_title = "RES"
)
# Add polarisation
p3.scale <- p2 + new_scale_fill() # add new scale for third variable
# Add pol
p3 <- gheatmap(p3.scale, (Poldf),
offset = 0.36, # to avoid overlapping with p1
width = 0.04, low = "gray90", high = "#648fff",
font.size = 2.2,
colnames_position = "bottom", colnames_angle = 90,
colnames_offset_x = 0, colnames_offset_y = -0.5,
legend_title = "POL"
)
# Add a white column
p4.scale <- p3 + new_scale_fill() # add new scale
# Add a blank column. This is a trick to keep the branches short:
p4 <- gheatmap(p4.scale, (Poldf),
offset = 2, # to avoid overlapping with p1
width = 0.04, low = "white", high = "white",
font.size = 0.01,
colnames_position = "bottom", colnames_angle = 0,
colnames_offset_x = 0, colnames_offset_y = -0.5,
legend_title = " ",
)
Print:
p4 +
theme(legend.position = 'left',
legend.background = element_rect(),
legend.key = element_blank(), # removes the border
legend.key.size = unit(0.4, 'cm'), # sets overall area/size of the legend
legend.text = element_text(size = 8), # text size
title = element_text(size = 8))+
geom_tiplab(size=2.76, # add names
offset = 0.57, # this adjusts the position of the species names
aes(label= paste0('italic(', label, ')')), # sppnames in italics
parse=TRUE) # allows us to alter the tips label