我正在尝试使用phytools软件包在系统发育图上绘制特征数据。我敢肯定这应该很简单,但是我收到一条无用的错误消息,而且我不知道该怎么办。
这是我的代码,包括数据下载。
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<button onclick="getLocation()">Try It</button>
<p id="result"></p>
<script>
var result = document.getElementById("result");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.watchPosition(showPosition, null, { enableHighAccuracy: true });
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
result.innerHTML = "latitude: " + position.coords.latitude +
"<br>longitude: " + position.coords.longitude +
"<br>position accuracy: " + position.coords.accuracy + " [m]" +
"<br>altitude: " + position.coords.altitude + " [m]" +
"<br>altitude accuracy: " + position.coords.altitudeAccuracy + " [m]" +
"<br>heading: " + position.coords.heading + " [degrees]" +
"<br>speed: " + position.coords.speed + " [m/s]";
}
</script>
</body>
</html>
我尝试绘制树和完整树的较小子集,但在两种情况下都出现错误:
# General
library(dplyr)
# Phylogenetic libraries.
library(caper)
library(phytools)
#+ data_read
p <- read.table(file = 'http://esapubs.org/archive/ecol/E090/184/PanTHERIA_1-0_WR05_Aug2008.txt',
header = TRUE, sep = "\t", na.strings = c("-999", "-999.00"))
## Some data cleaning
# Remove NAs in response and response where litter size is less than one (doesn't make sense).
p <- p %>%
filter(!is.na(X15.1_LitterSize)) %>%
filter(X15.1_LitterSize >= 1) %>%
mutate(y = log1p(X15.1_LitterSize)) %>%
dplyr::select(-X15.1_LitterSize, -References, -X24.1_TeatNumber)
## Get phylogeny data.
### read in phylogeny data.
# Read in trees
tree <- read.nexus('https://onlinelibrary.wiley.com/action/downloadSupplement?doi=10.1111%2Fj.1461-0248.2009.01307.x&file=ELE_1307_sm_SA1.tre')
# Select best supported tree
tree <- tree[[1]]
tree$tip.label <- gsub('_', ' ', tree$tip.label)
# Check if species are available.
mean(p$MSW05_Binomial %in% tree$tip.label)
in_phylo <- p$MSW05_Binomial %in% tree$tip.label
# Remove data that is not in the phylogeny.
p <- p %>% filter(in_phylo)
# Try just vulpes.
unneededTips <- tree$tip.label[!grepl('Vulpes', tree$tip.label) | !(tree$tip.label %in% p$MSW05_Binomial)]
# Prune tree down to only needed tips.
pruneTree <- drop.tip(tree, unneededTips)
dotTree(pruneTree, p$y[grepl('Vulpes', p$MSW05_Binomial)])
# Try all species
unneededTips <- tree$tip.label[!(tree$tip.label %in% p$MSW05_Binomial)]
# Prune tree down to only needed tips.
pruneTree <- drop.tip(tree, unneededTips)
dotTree(pruneTree, p$y)
答案 0 :(得分:1)
dotTree
和phytools
中类似功能(例如contMap
)的,您的特征值必须是一个命名向量,其名称与树中的提示相对应。
在您的示例中,您需要确保p$y
是一个命名向量({{1}应该是!is.null(names(p$y))
):
TRUE
您可以对较大的树应用相同的过程。
建议您使用## Prune down the non Vulpes tips
vulpes_tree <- drop.tip(tree, tree$tip.label[-grep("Vulpes", tree$tip.label)])
## Naming the variables in p$y
all_vulpes <- grepl('Vulpes', p$MSW05_Binomial)
traits_to_plot <- p$y[all_vulpes]
names(traits_to_plot) <- p$MSW05_Binomial[all_vulpes]
## Plotting the Vulpes and the traits
dotTree(vulpes_tree, traits_to_plot)
包中的函数cleand.data
来匹配树和数据集:
dispRity