I am sure this has been answered somewhere, but I am not able to find a solution that has worked for me. I am trying to plot a graphic, but the top and bottom keeps going off the edge of the plot.
I should note that I am using RGui, not R Studio.
I had thought setting margins to par(mar=c(0,0,0,0)
would have worked, but it did not. I tried assigning non-zero values to the margins, but that made it worse. I also tried using mai
instead of mar
, with no improvement. I saw some posts suggesting dev.new()
, but that also did not work (and maybe that’s because I am not using R Studio?). What alternatives should I attempt?
Below is some portions of my code, which deal with plotting.
par(mar=c(0,0,0,0))
#Plot simmap results
plotTree(pruned_tree,type="fan",ftype="i",fsize=0.4,offset=10,lwd=1)
par(fg="transparent",lend=1)
plotTree(pruned_tree,type="fan",ftype="i",fsize=0.4,offset=10,lwd=1,color="white",add=TRUE)
for(i in 1:length(char1.simmap)) plot(char1.simmap[[i]],colors=sapply(cols,make.transparent,alpha=0.01),add=TRUE,lwd=1,type="fan",ftype="i",fsize=0.4,offset=10)
par(fg="black")
#Plot terminal states
pp<-get("last_plot.phylo",envir=.PlotPhyloEnv)
h<-max(nodeHeights(pruned_tree))
obj<-summary(char1.simmap)$ace[1:pruned_tree$Nnode,]
par(lend=3)
for(i in 1:Ntip(pruned_tree)){
cc<-if(pp$xx[i]>0) 0.05 else -0.05 #Adjusts size of terminal state boxes
th<-atan(pp$yy[i]/pp$xx[i])
segments(pp$xx[i],pp$yy[i],pp$xx[i]+cc*cos(th),pp$yy[i]+cc*sin(th),lwd=14,col=cols[Metapleuron.process[pruned_tree$tip.label[i]]])}
#Plot internal pie charts
ii<-order(rowSums(obj^2),decreasing=TRUE)
for(i in ii){
plotrix::floating.pie(pp$xx[i+Ntip(pruned_tree)],pp$yy[i+Ntip(pruned_tree)],radius=if(max(obj[i,])<0.90) 0.03*h else 0.015,x=obj[i,],col=cols)
}
#Plot clade labels
arc.cladelabels(text="",node=which(pruned_tree$tip.label=="Maevius_indecorus_SRR6413622"),orientation="horizontal",cex=0.4,ln.offset=1.85,lab.offset=2.31,lwd=20,col="#66a61e",mark.node=FALSE)
arc.cladelabels(text="",node=findMRCA(pruned_tree, c("Leptocoris_sp_CMF_0673","Maccevethus_errans_CMF_0986")),cex=0.4,ln.offset=1.85,lab.offset=2.31,lwd=20,col="#bd0026",mark.node=FALSE,stretch=1)
arc.cladelabels(text="",node=which(pruned_tree$tip.label=="Dicranocephalus_haoussa_CMF_0718"),orientation="horizontal",cex=0.4,ln.offset=1.85,lab.offset=2.31,lwd=20,col="#7570b3",mark.node=FALSE)
arc.cladelabels(text="",node=findMRCA(pruned_tree, c("Hydarella_chiangdaoensis_CMF_1129","Madura_fuscoclavata_CMF_1078")),cex=0.4,ln.offset=1.85,lab.offset=2.31,lwd=20,col="#006d2c",mark.node=FALSE)
arc.cladelabels(text="",node=findMRCA(pruned_tree, c("Micrelytra_fossularum_CMF_0910","Stenocoris_tipuloides_CMF_0174")),cex=0.4,ln.offset=1.85,lab.offset=2.31,lwd=20,col="#6a51a3",mark.node=FALSE)
arc.cladelabels(text="",node=findMRCA(pruned_tree, c("Neomegalotomus_rufipes_CMF_0098_TD60","Heegeria_tangirica_CMF_0961")),cex=0.4,ln.offset=1.85,lab.offset=2.31,lwd=20,col="#6a51a3",mark.node=FALSE)
arc.cladelabels(text="",node=findMRCA(pruned_tree, c("Gralliclava_horrens_CMF_1165","Coriomeris_denticulatus_CMF_0979")),cex=0.4,ln.offset=1.85,lab.offset=2.31,lwd=20,col="#006d2c",mark.node=FALSE)
arc.cladelabels(text="",node=findMRCA(pruned_tree, c("Discogaster_dentipes_CMF_1052","Lucullia_flavovittata_CMF_1021")),cex=0.4,ln.offset=1.85,lab.offset=2.31,lwd=20,col="#006d2c",mark.node=FALSE)
arc.cladelabels(text="",node=findMRCA(pruned_tree, c("Leptocoris_sp_CMF_0673","Jadera_haematoloma_CMF_0281")),ln.offset=1.75,lab.offset=2.06,,lwd=20,col="#fc4e2a",mark.node=FALSE)
arc.cladelabels(text="",node=findMRCA(pruned_tree, c("Liorhyssus_hyalinus_CMF_0898","Maccevethus_errans_CMF_0986")),cex=0.4,ln.offset=1.75,lab.offset=2.06,lwd=20,col="#e31a1c",mark.node=FALSE)
arc.cladelabels(text="",node=findMRCA(pruned_tree, c("Hydarella_chiangdaoensis_CMF_1129","Madura_fuscoclavata_CMF_1078")),cex=0.4,ln.offset=1.75,lab.offset=2.06,lwd=20,col="#74c476",mark.node=FALSE)
arc.cladelabels(text="",node=findMRCA(pruned_tree, c("Micrelytra_fossularum_CMF_0910","Stenocoris_tipuloides_CMF_0174")),cex=0.4,ln.offset=1.75,lab.offset=2.06,lwd=20,col="#9e9ac8",mark.node=FALSE)
arc.cladelabels(text="",node=findMRCA(pruned_tree, c("Neomegalotomus_rufipes_CMF_0098_TD60","Heegeria_tangirica_CMF_0961")),cex=0.4,ln.offset=1.75,lab.offset=2.06,lwd=20,col="#807dba",mark.node=FALSE)
arc.cladelabels(text="",node=findMRCA(pruned_tree, c("Gralliclava_horrens_CMF_1165","Coriomeris_denticulatus_CMF_0979")),cex=0.4,ln.offset=1.75,lab.offset=2.06,lwd=20,col="#41ab5d",mark.node=FALSE)
arc.cladelabels(text="",node=findMRCA(pruned_tree, c("Discogaster_dentipes_CMF_1052","Lucullia_flavovittata_CMF_1021")),cex=0.4,ln.offset=1.75,lab.offset=2.06,lwd=20,col="#238443",mark.node=FALSE)
arc.cladelabels(text="",node=which(pruned_tree$tip.label=="Liorhyssus_hyalinus_CMF_0898"),cex=0.4,ln.offset=1.65,lab.offset=1.81,lwd=20,col="#fed976",mark.node=FALSE)
arc.cladelabels(text="",node=which(pruned_tree$tip.label=="Harmostes_serratus_CMF_0401"),cex=0.4,ln.offset=1.65,lab.offset=1.81,lwd=20,col="#feb24c",mark.node=FALSE)
arc.cladelabels(text="",node=findMRCA(pruned_tree, c("Corizus_hyoscyami_CMF_0973","Rhopalus_parumpunctatus_CMF_0993")),cex=0.4,ln.offset=1.65,lab.offset=1.81,lwd=20,col="#fed976",mark.node=FALSE)
arc.cladelabels(text="",node=findMRCA(pruned_tree, c("Myrmus_miriformis_CMF_0982","Chorosoma_schillingii_CMF_0933")),cex=0.4,ln.offset=1.65,lab.offset=1.81,lwd=20,col="#fd8d3c",mark.node=FALSE)
arc.cladelabels(text="",node=findMRCA(pruned_tree, c("Stictopleurus_abutilon_CMF_0983","Maccevethus_errans_CMF_0986")),cex=0.4,ln.offset=1.65,lab.offset=1.81,lwd=20,col="#fed976",mark.node=FALSE)
arc.cladelabels(text="",node=findMRCA(pruned_tree, c("Mutusca_brevicornis_CMF_0417","Stenocoris_tipuloides_CMF_0174")),cex=0.4,ln.offset=1.65,lab.offset=1.81,lwd=20,col="#bcbddc",mark.node=FALSE)
arc.cladelabels(text="",node=findMRCA(pruned_tree, c("Micrelytra_fossularum_CMF_0910","Dulichius_trispinosus_CMF_0906")),cex=0.4,ln.offset=1.65,lab.offset=1.81,lwd=20,col="#dadaeb",mark.node=FALSE)
arc.cladelabels(text="",node=findMRCA(pruned_tree, c("Gralliclava_horrens_CMF_1165","Clavigralla_pusilla_CMF_0952_0960")),cex=0.4,ln.offset=1.65,lab.offset=1.81,lwd=20,col="#ffffd9",mark.node=FALSE)
arc.cladelabels(text="",node=findMRCA(pruned_tree, c("Vilga_sanctipauli_CMF_1048","Coriomeris_denticulatus_CMF_0979")),cex=0.4,ln.offset=1.65,lab.offset=1.81,lwd=20,col="#ffffcc",mark.node=FALSE)
arc.cladelabels(text="",node=findMRCA(pruned_tree, c("Discogaster_dentipes_CMF_1052","Mozena_lunata_CMF_0008")),cex=0.4,ln.offset=1.65,lab.offset=1.81,lwd=20,col="#f7fcb9",mark.node=FALSE)
arc.cladelabels(text="",node=findMRCA(pruned_tree, c("Sephina_geniculata_CMF_0172","Acanthocoris_sordidus_CMF_0276_TD50")),cex=0.4,ln.offset=1.65,lab.offset=1.81,lwd=20,col="#edf8b1",mark.node=FALSE)
arc.cladelabels(text="",node=findMRCA(pruned_tree, c("Cloresmus_antennatus_CMF_0634","Plectropoda_cruciata_CMF_0037")),cex=0.4,ln.offset=1.65,lab.offset=1.81,lwd=20,col="#d9f0a3",mark.node=FALSE)
arc.cladelabels(text="",node=findMRCA(pruned_tree, c("Odontocurtus_consociatus_CMF_0694","Latimbus_concolor_CMF_0827")),cex=0.4,ln.offset=1.65,lab.offset=1.81,lwd=20,col="#c7e9b4",mark.node=FALSE)
arc.cladelabels(text="",node=findMRCA(pruned_tree, c("Galaesus_hasticornis_CMF_0701","Cletus_ochraceus_CMF_0152_TD55")),cex=0.4,ln.offset=1.65,lab.offset=1.81,lwd=20,col="#addd8e",mark.node=FALSE)
arc.cladelabels(text="",node=findMRCA(pruned_tree, c("Villasitocoris_inconspicuus_CMF_0822","Lucullia_flavovittata_CMF_1021")),cex=0.4,ln.offset=1.65,lab.offset=1.81,lwd=20,col="#78c679",mark.node=FALSE)
legend(x="topleft",levels(Metapleuron.process),pch=22,pt.bg=cols,pt.cex=1.5,bty="n",cex=0.8)