1

Goal

enter image description here

Code

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

Helper questions

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

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

Community
  • 1
  • 1
hhh
  • 50,788
  • 62
  • 179
  • 282
  • 2
    http://cran.r-project.org/web/packages/gridBase/index.html – rcs Aug 18 '12 at 19:30
  • I hope I did not change the question. By "grid grahpics", I mean stuff like in the picture. Beware the confusion, I do not mean just the things by the Grid -pkg. I am unsure whether I should I ask the question like `"How should I create grid-graphics?"` -- to make it sure that I am interested to find out also opnions for-and-against different approaches... – hhh Aug 18 '12 at 20:39

2 Answers2

3

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

gridBase example

rcs
  • 67,191
  • 22
  • 172
  • 153
  • What is your opinion about mixing different syntaxes together to create Grid-graphics like the picture in q? MR discouraged it in #R and suggested to use consistenly one format. – hhh Aug 18 '12 at 20:43
  • 1
    I would also be consistent; I prefer `ggplot2` but I also use `lattice` sometimes. – rcs Aug 18 '12 at 20:53
  • So you suggest me to use `ggplot2` for grid-graphics -generation? Comparison between ggplot2 and lattice [here](http://stackoverflow.com/questions/2759556/r-what-are-the-pros-and-cons-of-using-lattice-versus-ggplot2). So for a newbie like me it is better to start learning the ggplot2 instead of playing with this combination -pkg and inconsistencies? – hhh Aug 18 '12 at 20:55
  • I did not fully understand: did you suggest not use gridBase? I cannot yet understand whether I can do all GridGraphics with ggplot2 without gridBase. – hhh Aug 19 '12 at 13:55
0

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

enter image description 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.

Community
  • 1
  • 1
hhh
  • 50,788
  • 62
  • 179
  • 282