r - 从由两个饼图组成的图中消除死区

标签 r plot pie-chart

我有这个图,我想保存为 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()

这就是我得到的

enter image description here

它看起来很不错,但我想尽可能消除单个饼图之间以及它们与图例之间的空白空间。有什么建议?

最佳答案

layout() ,我认为您可能会在更改边距以将饼图挤压在一起时受到一些限制。

这不是一个优雅的解决方案,但它有效。我去了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

关于r - 从由两个饼图组成的图中消除死区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34601842/

相关文章:

r - 在 Facebook 中使用 try Catch 或其他处理调用 API 错误

r - 为什么 lmerTest 不为某些模型提供 p 值?

haskell - 无法成功安装plot Haskell

python - Bokeh 图上的多个 slider

c++ - 如何让 Armadillo 函数在反转奇异矩阵时不打印错误?

r - R 中的一致错误管理

r - 显示方位和距离的圆图

Python matplotlib.pyplot 饼图 : How to remove the label on the left side?

python - 如何为每组 pandas 列创建一个子图

java - 通过 css 设置 JavaFX PieChart 标签颜色