My code is:
x<-setNames(X$x,rownames(X))
par(mfrow=c(1,2))
plot(tree,show.tip.label=FALSE,no.margin=TRUE)
par(fg="transparent")
tiplabels(pie=to.matrix(x[tree$tip.label],c("1","2")),piecol=c("blue","red"),cex=0.3)
Error in seq.default(x[i], x[i + 1], length = n) : 'to' must be a finite number