R phylogeny plot together with barplot
1
0
Entering edit mode
10.0 years ago
dsarbashis ▴ 90

Hi All,

I was trying to plot a phylogeny tree along with bar plot side by side. I am using the following code. The problem is that my bar plot extend outside the right margin. Any help is appreciated. Thanks in advance.

TREE <- rcoal(10)
tip.order <- TREE$tip.label[TREE$edge[TREE$edge[, 2] <= Ntip(TREE), 2]]
tip.order

data<-matrix(seq(1:10),nrow = 10,ncol = 1,byrow = T)
rownames(data)<-apply(data,1, function(x) paste('t',x,sep = ''))

dordered<-data[tip.order,]

plot(TREE,x.lim=5)

barplot(c(NA,dordered),add=T,horiz = T,space = 0,offset = 1.4,axes = F,axisnames = F,width = 0.95,xlim = (0:10),par(pin=c(1,8)))

lab<-dordered
axis(1,lab + 1.2,label=lab,cex.axis=0.4,padj=0)
R • 4.1k views
ADD COMMENT
0
Entering edit mode

please provide a reproducible example

ADD REPLY
0
Entering edit mode

Thanks. I updated the code.

ADD REPLY
2
Entering edit mode
10.0 years ago
komal.rathi ★ 4.1k

You need to increase the x.lim value when you create the plot. Any value > 10 would do.

plot(TREE, x.lim = 11)

You are setting x.lim = 5 and then trying to add another plot with limits barplot(...xlim = c(0,10)...) that exceeds the previous one.

ADD COMMENT
0
Entering edit mode

Thanks komal. Got it.

ADD REPLY

Login before adding your answer.

Traffic: 2670 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6