0

I need to have these two piecharts and the legend in the middle, how can I determine the position of a legend to be exactly in the middle, so it will not overlap the piecharts.

par(mfrow = c(1,2)) 
pie(frman, main="Men", col=cols, labels=pielabelsman, cex=0.85)
pie(frwoman, main="Women", col=cols,labels=pielabelswoman,cex=0.85)
legend("center", uniq, cex=0.5,fill=cols)

enter image description here

arghtype
  • 4,376
  • 11
  • 45
  • 60

1 Answers1

0

You can place the legend in different places by default commands:

legend("center", uniq, cex=0.5,fill=cols)    
legend("bottomright", uniq, cex=0.5,fill=cols)
legend("bottom", uniq, cex=0.5,fill=cols)
legend("bottomleft", uniq, cex=0.5,fill=cols)
legend("left", uniq, cex=0.5,fill=cols)
legend("topleft", uniq, cex=0.5,fill=cols)
legend("top", uniq, cex=0.5,fill=cols)
legend("topright", uniq, cex=0.5,fill=cols)
legend("right", uniq, cex=0.5,fill=cols)
legend("center", uniq, cex=0.5,fill=cols)

Otherwise you can specify it yourself by inputting the x and y coordinates, for instance:

legend(x = 2, y = 5 , uniq, cex=0.5,fill=cols)

You can find more information here, here, here or here, just to give some examples.

UPDATE

You can also try with:

layout(matrix(c(1,2,3,3), ncol=2, byrow=TRUE), heights=c(4, 1))
par(mai=rep(0.5, 4)) 
pie(frman, main="Men", col=cols, labels=pielabelsman, cex=0.85)
pie(frwoman, main="Women", col=cols,labels=pielabelswoman,cex=0.85)
par(mai=c(0,0,0,0))
plot.new()
legend("center", uniq, cex=0.5,fill=cols)

As I don't have your data I can't check whether it looks right or not, but I think it should.

Community
  • 1
  • 1
adrian1121
  • 904
  • 2
  • 9
  • 21