R:我应该如何创建网格图形? [英] R: How should I create Grid-graphics?

查看:143
本文介绍了R:我应该如何创建网格图形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标

代码

require(lattice)

png('my_typing.png')
par(mfrow=c(2,1))

read.csv('race_data.csv')->sol
plot(sol$Race.., sol$WPM*sol$Accuracy, type='l')

# TODO: it wrongly substitutes the plot with levelplot
# TODO: I want two plots one below another, plot and then levelplot below
levelplot(cor(sol[1:5]))

帮助者问题

  1. 如何在一个PNG文件中一起绘制法线图和特殊图?

  1. How can I plot the normal plot and the special plot together in one PNG -file?

我应该将不同的绘图包(例如晶格和网格)组合到基础上吗?

Should I combine different plotting -packages such as lattice and grid to base?

推荐答案

The gridBase package which provides some support for combining grid and base graphics output.

这是一个简单的例子:

library("grid")
library("gridBase")
library("lattice")

# example from levelplot help page
x <- seq(pi/4, 5 * pi, length.out = 100)
y <- seq(pi/4, 5 * pi, length.out = 100)
r <- as.vector(sqrt(outer(x^2, y^2, "+")))
g <- expand.grid(x=x, y=y)
g$z <- cos(r^2) * exp(-r/(pi^3))
p <- levelplot(z~x*y, g, cuts = 50, scales=list(log="e"), xlab="",
               ylab="", main="lattice levelplot",
               colorkey=FALSE, region=TRUE)

grid.newpage()
pushViewport(viewport(layout=grid.layout(2, 1,
                                         heights=unit(c(2, 1), "null"))))
vp <- pushViewport(viewport(layout.pos.row=1, layout.pos.col=1))
par(omi=gridOMI())
# base graphics
plot(1:10, main="base graphics plot")
popViewport()
# lattice plot
vp <- pushViewport(viewport(layout.pos.row=2, layout.pos.col=1))
print(p, vp=vp, newpage=FALSE)
popViewport()
popViewport()

这篇关于R:我应该如何创建网格图形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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