emmanuelparadis / pegas

Population and Evolutionary Genetics Analysis System
GNU General Public License v2.0
28 stars 10 forks source link

Changing node coordinates changes node scale #83

Closed naurasd closed 1 year ago

naurasd commented 1 year ago

Hi

I am generating a png file of a haplotype network with the code below:

png("motu24_all_frac_haplotype_network.png",type="cairo",units="in",width=10,height=10,res=400)
xy<-plot(nt, size = sz,pie=R,bg=pal,labels=F,xlim=c(-30,40),ylim=c(-25,25),show.mutation = 2)
dev.off()

This generates the following image: grafik

Let's say I just want to shift my nodes along either the y- or x-axis. I am shifting all of my nodes along the y-axis with the following code:

png("motu24_all_frac_haplotype_network2.png",type="cairo",units="in",width=10,height=10,res=400)
xy<-plot(nt, size = sz,pie=R,bg=pal,labels=F,xlim=c(-30,40),ylim=ylim=c(-25,25),show.mutation = 2)
xy$yy<-xy$yy+10 
xz<-replot(xy) # Replot
dev.off()

This generates the following image: grafik As you can see, despite neither changing the dimension of the png, nor xlim or ylim, The nodes now appear much larger than before. But to my understanding, all I have done is shifting the entire network up by a value of 10 along the y-axis.

Why does the scale of the nodes change in this case?

Thanks Nauras

emmanuelparadis commented 1 year ago

Hi, It's true that replot() does not respect xlim and/or ylim if they were set in the previous call to plot(). But, you should avoid to use replot() non-interactively. Instead, try something like in the example code in ?replot, such as:

example(replot)
plot(ntz, xy = xy) # suppose this is the plot you want but you need more space on the right-hand side
plot(ntz, xy = xy, xlim = c(1, 12))

Once you found the appropriate values of xlim and xy, you can do:

png("............
plot(ntz, xlim = c(1, 12), xy = xy)
dev.off()

Cheers, E.

naurasd commented 1 year ago

Thanks for the quick reply on all my questions. this solution worked like a charm ;-)