如果输入较大的数字,R 金字塔图会非常慢 [英] R pyramid plot very slow if fed with larger numbers

查看:57
本文介绍了如果输入较大的数字,R 金字塔图会非常慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用 R 制作金字塔图.我在互联网上找到了一个可以做我想做的示例代码.问题是我没有像示例中那样使用小数字.我的图的值为 3,000,000 到 12,000,000,但每边只有 10 个条形.永远用更大的数字创建绘图所需的时间更少,输出的 pdf 文件大小约为 800mb.

I am trying make a pyramid plot with R. The I found a example code in the internet that does what I want. The problem is that I am not working with small numbers as in the example. My plot has values of 3,000,000 to 12,000,000 but only 10 bars per side. Never the less it takes for ever create the plot with the larger numbers and output pdf file is about 800mb of size.

pyramid.plot(x,y,labels=groups,main="Performance",lxcol=mcol,rxcol=fcol,gap=0.5,show.values=TRUE)

为什么性能这么差?不应该自动缩放吗?

Why is the performance so bad? Shouldn't get scaled automatically?

更新:

pdf(file='figure1.pdf')
library(plotrix)

x <-c(3105000,3400001,4168780,2842764,3543116,4224601,4222222,6432105,9222222,12345596)
y <-c(3105000,3400001,4168780,2842764,3543116,4224601,4222222,6432105,9222222,12345596)
groups <-c("g1","g2","g3","g4","g5","g6","g7","g8","g9","g11") 
pyramid.plot(x,y,labels=groups,main="Performance",gap=0.5,show.values=TRUE)
dev.off()

导出为 pdf 以及绘图屏幕都需要几分钟.

Both the export to pdf as well as the plotting screen takes multiple minutes.

推荐答案

在内部,pyramid.plot 正在尝试做一些事情来解决占中间间隙的轴:如果你这样做debug(pyramid.plot) 并逐行逐行查找问题所在:

Internally, pyramid.plot is trying to do some stuff to finagle the axes accounting for the gap in the middle: if you do debug(pyramid.plot) and step through line-by-line you find where the problem is:

if (is.null(laxlab)) {
            laxlab <- seq(xlim[1] - gap, 0, by = -1)
            axis(1, at = -xlim[1]:-gap, labels = laxlab)
        }

换句话说,pyramid.plot 试图制作一个每 1 (!) 个单位带有刻度的轴.像这样的工作正常:

in other words, pyramid.plot is trying to make an axis with ticks every 1 (!) unit. Something like this works OK:

pyramid.plot(x,y,labels=groups,
             main="Performance",gap=5e5,show.values=TRUE,
             laxlab=seq(0,1e7,by=1e6),raxlab=seq(0,1e7,by=1e6))

还有一些其他迹象表明 pyramid.plot 是为人口统计图设计的……你可以写信给包维护者,让他考虑概括轴的设计有点……

there are a few other vestiges of the fact that pyramid.plot was designed for demographic plots ... you might write to the package maintainer and ask him to think about generalizing the design of the axes a little bit ...

这篇关于如果输入较大的数字,R 金字塔图会非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆