2012-12-21 57 views
1

我正在尝试创建饼图,如here,但图例和实际饼图重叠。饼图和图例重叠

我使用的代码是在这里:

library(ggplot2) 
library(grid) 

par(mai = c(1,1,1,1)) 

numb <- c(41, 30, 21, 8) 
colors <- c("black", "grey70", "grey30","white") 

numb_labels <- round(numb/sum(numb) * 100, 1) 
numb_labels <- paste(numb_labels, "%", sep="") 
xx <- c("the process of familiarizing with the codebase", 
     "the patch review process", 
     "the impact on the users of the project", 
     "high degree visibility of the contributions") 

pie(numb, col=colors, labels=numb_labels, clockwise=TRUE) 

legend("top", legend = xx, fill=colors, bty="n") 

有人能帮助我吗?

+2

据我所知''grid'和'ggplot2'是红色鲱鱼 - 这里的一切似乎都是基础R,你不需要加载那些包(应该是无害的) –

回答

3

我不知道你为什么附加ggplot2

您可以使用layout

par(mai = c(0,0,0,0)) 
layout(c(1,2),heights=c(0.3,1)) 
plot.new() 
legend("bottom", legend = xx, fill=colors, bty="n") 
pie(numb, col=colors, labels=numb_labels, clockwise=TRUE) 
2

一种解决方案是使用参数xpd=TRUE和函数par(),然后在图例区域外以图例坐标设置图例。

par(xpd=TRUE) 
pie(numb, col=colors, labels=numb_labels, clockwise=TRUE) 
legend(-1.4,1.6, legend = xx, fill=colors, bty="n") 
0

面值(MAI = C(1,1,4,1),XPD = TRUE)

馅饼(麻木,山坳=颜色,标签= numb_labels顺时针= TRUE)

说明( “顶部”,插图= C(0,-0.5),CEX = 0.9,图例= XX,填充=颜色,BTY = “N”)

注意:首先插入元素水平移动你的图例,第二个垂直移动。 cex参数可以调整您的图例。所以可以通过改变这些参数值来调整你的图例。