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 - 如何使用 ggplot 中的分组箱线图将 geom_text 标签放置在正确的位置

Matlab实时绘制来自串口的多个数据

pandas - 如何更改 DataFrame 中堆积区域图的填充颜色?

r - 将两个饼图合二为一

javascript - ChartJs饼图例位置

r - 为什么 approx 返回一个列表而不是一个数据框或数组?

r - R:如何制作带有平行于(水平)标签的条形图

r - 用 R 绘制维恩图?

matlab - 创建极坐标直方图

javascript - 如何在 pie amcharts 中只获取某些数据?