File: translate-qplot-lattice.r

package info (click to toggle)
r-cran-ggplot2 1.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 4,412 kB
  • sloc: sh: 9; makefile: 1
file content (77 lines) | stat: -rw-r--r-- 3,011 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#' Translating between qplot and lattice
#'
#' The major difference between lattice and ggplot2 is that lattice uses a formula based
#' interface. ggplot2 does not because the formula does not generalise well
#' to more complicated situations.
#'
#' @name translate_qplot_lattice
#' @examples
#' \donttest{
#' library(lattice)
#'
#' xyplot(rating ~ year, data=movies)
#' qplot(year, rating, data=movies)
#'
#' xyplot(rating ~ year | Comedy + Action, data = movies)
#' qplot(year, rating, data = movies, facets = ~ Comedy + Action)
#' # Or maybe
#' qplot(year, rating, data = movies, facets = Comedy ~ Action)
#'
#' # While lattice has many different functions to produce different types of
#' # graphics (which are all basically equivalent to setting the panel argument),
#' # ggplot2 has qplot().
#'
#' stripplot(~ rating, data = movies, jitter.data = TRUE)
#' qplot(rating, 1, data = movies, geom = "jitter")
#'
#' histogram(~ rating, data = movies)
#' qplot(rating, data = movies, geom = "histogram")
#'
#' bwplot(Comedy ~ rating ,data = movies)
#' qplot(factor(Comedy), rating, data = movies, type = "boxplot")
#'
#' xyplot(wt ~ mpg, mtcars, type = c("p","smooth"))
#' qplot(mpg, wt, data = mtcars, geom = c("point","smooth"))
#'
#' xyplot(wt ~ mpg, mtcars, type = c("p","r"))
#' qplot(mpg, wt, data = mtcars, geom = c("point","smooth"), method = "lm")
#'
#' # The capabilities for scale manipulations are similar in both ggplot2 and
#' # lattice, although the syntax is a little different.
#'
#' xyplot(wt ~ mpg | cyl, mtcars, scales = list(y = list(relation = "free")))
#' qplot(mpg, wt, data = mtcars) + facet_wrap(~ cyl, scales = "free")
#'
#' xyplot(wt ~ mpg | cyl, mtcars, scales = list(log = 10))
#' qplot(mpg, wt, data = mtcars, log = "xy")
#'
#' xyplot(wt ~ mpg | cyl, mtcars, scales = list(log = 2))
#' library(scales)  # Load scales for log2_trans
#' qplot(mpg, wt, data = mtcars) + scale_x_continuous(trans = log2_trans()) +
#'   scale_y_continuous(trans = log2_trans())
#'
#' xyplot(wt ~ mpg, mtcars, group = cyl, auto.key = TRUE)
#' # Map directly to an aesthetic like colour, size, or shape.
#' qplot(mpg, wt, data = mtcars, colour = cyl)
#'
#' xyplot(wt ~ mpg, mtcars, xlim = c(20,30))
#' # Works like lattice, except you can't specify a different limit
#' # for each panel/facet
#' qplot(mpg, wt, data = mtcars, xlim = c(20,30))
#'
#' # Both lattice and ggplot2 have similar options for controlling labels on the plot.
#'
#' xyplot(wt ~ mpg, mtcars, xlab = "Miles per gallon", ylab = "Weight",
#'   main = "Weight-efficiency tradeoff")
#' qplot(mpg, wt, data = mtcars, xlab = "Miles per gallon", ylab = "Weight",
#'   main = "Weight-efficiency tradeoff")
#'
#' xyplot(wt ~ mpg, mtcars, aspect = 1)
#' qplot(mpg, wt, data = mtcars, asp = 1)
#'
#' # par.settings() is equivalent to + theme() and trellis.options.set()
#' # and trellis.par.get() to theme_set() and theme_get().
#' # More complicated lattice formulas are equivalent to rearranging the data
#' # before using ggplot2.
#' }
NULL