2017-04-13 136 views
0

我需要在中間有這兩個餅圖和圖例,我如何確定圖例的位置正好在中間,所以它不會重疊的餅圖。確定R中圖例的位置,因此傳說不會重疊餅圖

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

回答

0

您可以通過默認命令放置在不同的地方傳說:

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) 

否則,您可以通過輸入x和y座標,比如自己指定:

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

你可以找到更多的信息herehereherehere,只是舉一些例子。

UPDATE

您也可以嘗試:

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) 

由於我沒有數據,我不能檢查它是否看起來正確與否,但我認爲它應該。

+0

感謝您的回覆。我已經嘗試過使用不同的x和y值的最後一行,但我無法找到合適的x,y來觀察圖例。 –

+0

事情是我使用par(mfrow = c(1,2)),所以x,y對應於每次兩個圖中的一個 –

+0

@GiorgosVoultsios我更新了答案。如果有效,不要忘記註冊並接受答案!謝謝! – adrian1121