Question: R phylogeny plot together with barplot
0
gravatar for dsarbashis
6.2 years ago by
dsarbashis60
Germany
dsarbashis60 wrote:

 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 • 2.9k views
ADD COMMENTlink modified 6.2 years ago • written 6.2 years ago by dsarbashis60

please provide a reproducible example

ADD REPLYlink written 6.2 years ago by Michael Dondrup48k

Thanks. I updated the code.

ADD REPLYlink written 6.2 years ago by dsarbashis60
2
gravatar for komal.rathi
6.2 years ago by
komal.rathi3.7k
Children's Hospital of Philadelphia, Philadelphia, PA
komal.rathi3.7k wrote:

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 COMMENTlink modified 6.2 years ago • written 6.2 years ago by komal.rathi3.7k

Thanks komal. Got it.

ADD REPLYlink written 6.2 years ago by dsarbashis60
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1694 users visited in the last hour
_