如何制作一个可笑的广泛情节 [英] How to do a ridiculously wide plot
问题描述
我有一个很长的时间序列,我想可视化 10000 个观察结果.问题是,如果我只是正常绘制它,时间维度将被压缩,并且我想要可视化的时间序列的任何细节都不会明显.例如:
I have a long time series of 10000 observations that I want to visualize. The problem is, if I just plot it normally the time-dimension will be squished and none of the fine detail of the time-series that I want to visualize will be apparent. For example:
plot((sin(1:10000/100)+rnorm(10000)/5),type='l')
我想要的是在不使用 par(mfrow=c(1,100)) 的情况下,以某种方式在一个巨大的长图中并排绘制以下内容.然后我想导出这个非常广泛的情节,并简单地滚动以可视化整个系列.
What I would like is to somehow plot the following together side by side in one gigantically long plot without using par(mfrow=c(1,100)). I then want to export this very wide plot and simply scroll across to vizualise the whole series.
plot((sin(1:10000/100)+rnorm(10000)/5)[1:100],type='l')
plot((sin(1:10000/100)+rnorm(10000)/5)[101:200],type='l')
plot((sin(1:10000/100)+rnorm(10000)/5)[201:300],type='l')
.....
最终,我希望用 par(mfrow=c(4,1))
将 3 或 4 个这些巨大的地块重叠在一起.
Eventually I would like to have 3 or 4 of these gigantically wide plots on top of each other with a par(mfrow=c(4,1))
.
我知道答案与 par
中的 pin
设置有关,但我不断收到 Error in plot.new() : plot region太大
.我猜这与 pin
与其他 par
参数的交互有关
I know that the answer has something to do with the pin
setting in par
, but I keep getting Error in plot.new() : plot region too large
. I'm guessing this has something to do with the interaction of pin
with the other par
parameters
如果我们能够获得完全正确的像素高度和宽度,就会获得奖励积分.由于导出大小不完美,绘图最好不要跳过随机像素.
如果图像可以在 .html
中编码,则可以进一步加分.并以这种方式查看
Further bonus points if the image can be encoded in a .html
. and viewed this way
推荐答案
您可能考虑的另一种替代方案是 svg,它在任何情况下都会产生比 png/jpeg 更好的质量.
An alternative that you might consider is svg, which will produce something of better quality than png/jpeg in any case.
类似的东西
svg(width = 2000, height = 7)
par(mfrow=c(4,1), mar = c(4, 4, 0, 2))
for (i in 1:4){
plot((sin(1:10000/100)+rnorm(10000)/5),type='l',
bty = "l", xaxs = "i")
}
dev.off()
将生成一个非常宽的绘图,大小仅超过 1MB,这在 Chrome 中呈现得非常好.
will produce a very wide plot, just over 1MB in size, which renders quite nicely in Chrome.
注意这里的宽度和高度以英寸为单位.
Note the width and height are in inches here.
P.S. svg 还提供了交互式图形的潜力.刚刚看到一个很好的例子,允许用户选择一个长时间序列的区域进行放大,参见 Dynamic and Interactive R Graphics for the Web: The gridSVG Package,Paul Murrell 和西蒙·波特.
P.S. svg also offers the potential for interactive graphics. Just seen a nice example allowing the user to select a region of a long time series to zoom in on, see Figure 22 in Dynamic and Interactive R Graphics for the Web: The gridSVG Package, a draft paper by Paul Murrell and Simon Potter.
这篇关于如何制作一个可笑的广泛情节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!