R: How should I create Grid-graphics?

ぐ巨炮叔叔 提交于 2019-11-28 11:49:37

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

Here is a simple example:

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()

hhh

MR. in #R recommened to use just one type of plot -things. Trellis -functions are not interchangeable with the base functions so one should also reprogram the syntax for things such as trend-line and titles. Otherwise, you create syntantic confusing over time and consistency to dogs.

I am trying to find out alternative ways of doing Grid-graphics so the writing in progress.

Different ways of creating Grid-graphics

1. Trellis -way of doing things, using lattice -pkg, code here

2. Combining different plot -pkgs

MR. discouraged this way but rcs's way of doing it here. According to MR, grid is "much more user friendly way of creating grid grapics", so I think it is worth learning, and things such as lattice and ggplot2 are built on top of grid. Please, consult this paper about combining base -plotting-functions and the grid -plotting-functions here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!