Eliminate dead space from a plot consisting of two pie charts

I have this plot that I want to save as a PDF.

pdf(file="pie_charts.pdf", width=8, height=5, onefile=F)
layout(matrix(c(1,2,3,3), ncol=2, byrow=TRUE), heights=c(4, 1))
par(mar=c(0,0,0,0), xpd=TRUE)
pie(c(1,9),col=c("black","white"))
pie(c(1,3),col=c("black","white"))
plot.new()
legend(x="center", ncol=2,legend=c("Black","Whtie"),fill=c("black","white"), bty = "n",cex=1.3)
dev.off()

And this is what I get

enter image description here

This looks good, but I want to eliminate as much free space as possible between the individual pie charts, as well as between them and the legend. Any suggestions?

+4
source share
2 answers

Just increase the radiuspies:

layout(matrix(c(1, 2, 3, 3), ncol=2, byrow=TRUE), heights=c(4, 1))
par(mar=c(0, 1, 0, 0)) # increase left margin to accommodate text
pie(c(1, 9), col=c("black","white"), radius=1)
par(mar=c(0, 0, 0, 1)) # increase right margin to accommodate text
pie(c(1, 3), col=c("black", "white"), radius=1)
plot.new()
legend(x="center", ncol=2, legend=c("Black", "White"), 
       fill=c("black", "white"), bty="n", cex=1.3)

enter image description here

See radiusarg in ?pie.

+2
source

With layout(), I think, you can limit the margin change a bit to compress the pie charts together.

, . pie() xlim. .

, pie :

xlim <- ylim <- c(-1, 1)

xlim, .

mypieleft() mypieright().

mypieleft<-function(blah blah){
[untouched code from pie]
    #  xlim <- ylim <- c(-1, 1)
    xlim <- c(-1.20, 0.80)
    ylim <- c(-1, 1)
[untouched code from pie]
}

mypieright<-function(blah blah){
[untouched code from pie]
    #  xlim <- ylim <- c(-1, 1)
    xlim <- c(-0.75, 1.25)
    ylim <- c(-1, 1)
[untouched code from pie]
}

:

layout(matrix(c(1,2,3,3), ncol=2, byrow=TRUE), heights=c(4, 1))
par(oma=c(0,0,0,0), xpd=TRUE)
mypieleft(c(1,9),col=c("black","white"))
mypieright(c(1,3),col=c("black","white"))
plot.new()
legend(x="center", ncol=2,legend=c("Black","Whtie"),fill=c("black","white"), bty = "n",cex=1.3)

.

enter image description here

+3

Source: https://habr.com/ru/post/1622837/


All Articles