Skip to content

Commit 5551e1b

Browse files
committed
Fixes for examples
1 parent a2726d6 commit 5551e1b

12 files changed

+39
-53
lines changed

R/annotation-custom.r

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,13 @@ NULL
2424
#' # Dummy plot
2525
#' base <- qplot(1:10, 1:10, geom = "blank") + theme_bw()
2626
#' # Adding a table
27-
#' \donttest{
28-
#' require(gridExtra)
27+
#' \donttest{if (require(gridExtra)) {
2928
#' base + annotation_custom(grob = tableGrob(head(iris[ ,1:3])),
3029
#' xmin = 3, xmax = 6, ymin = 2, ymax = 8)
3130
#' # full panel
3231
#' base + annotation_custom(grob = roundrectGrob(),
3332
#' xmin = -Inf, xmax = Inf, ymin = -Inf, ymax = Inf)
34-
#' }
33+
#' }}
3534
#' # Inset plot
3635
#' g <- ggplotGrob(qplot(1, 1) +
3736
#' theme(plot.background = element_rect(colour = "black")))

R/facet-labels.r

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -103,26 +103,18 @@ label_wrap_gen <- function(width = 25) {
103103
#' \code{\link{facet_grid}} for the argument \code{labeller}.
104104
#' @export
105105
#' @examples
106-
#'
107-
#' data(mpg)
108-
#'
106+
#' \donttest{
109107
#' p1 <- ggplot(mpg, aes(cty, hwy)) + geom_point()
110-
#'
111-
#'
112108
#' p1 + facet_grid(cyl ~ class, labeller=label_both)
113-
#'
114109
#' p1 + facet_grid(cyl ~ class, labeller=labeller(cyl=label_both))
115110
#'
116111
#' ggplot(mtcars, aes(x = mpg, y = wt)) + geom_point() +
117112
#' facet_grid(vs + am ~ gear, margins=TRUE,
118113
#' labeller=labeller(vs=label_both, am=label_both))
119114
#'
120-
#'
121-
#'
122-
#' data(msleep)
123115
#' capitalize <- function(string) {
124116
#' substr(string, 1, 1) <- toupper(substr(string, 1, 1))
125-
#' string
117+
#' string
126118
#' }
127119
#' conservation_status <- c('cd'='Conservation Dependent',
128120
#' 'en'='Endangered',
@@ -132,22 +124,22 @@ label_wrap_gen <- function(width = 25) {
132124
#' 'domesticated'='Domesticated')
133125
#' ## Source: http://en.wikipedia.org/wiki/Uncyclopedia:Conservation_status
134126
#'
135-
#' p2 <- ggplot(msleep, aes(x=sleep_total, y=awake)) + geom_point() +
136-
#' p2 + facet_grid(vore ~ conservation, labeller=labeller(vore=capitalize))
127+
#' p2 <- ggplot(msleep, aes(x=sleep_total, y=awake)) + geom_point()
128+
#' p2 + facet_grid(vore ~ conservation, labeller = labeller(vore = capitalize))
137129
#'
138130
#' p2 + facet_grid(vore ~ conservation,
139-
#' labeller=labeller(vore=capitalize, conservation=conservation_status ))
131+
#' labeller=labeller(vore = capitalize, conservation = conservation_status ))
140132
#'
141133
#' # We could of course have renamed the levels;
142134
#' # then we can apply another nifty function:
143-
#' library(plyr)
144-
#' msleep$conservation2 <- revalue(msleep$conservation, conservation_status)
145-
#'
146-
#' p2 + facet_grid(vore ~ conservation2, labeller=labeller(vore=capitalize))
147-
#'
148-
#' p2 + facet_grid(vore ~ conservation2,
149-
#' labeller=labeller(conservation2=label_wrap_gen(10) ))
135+
#' msleep$conservation2 <- plyr::revalue(msleep$conservation, conservation_status)
150136
#'
137+
#' p2 %+% msleep +
138+
#' facet_grid(vore ~ conservation2, labeller = labeller(vore = capitalize))
139+
#' p2 %+% msleep +
140+
#' facet_grid(vore ~ conservation2, labeller = labeller(conservation2 =
141+
#' label_wrap_gen(10)))
142+
#' }
151143
labeller <- function(..., keep.as.numeric=FALSE) {
152144
args <- list(...)
153145

R/geom-dotplot.r

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
#'
6161
#' # y axis isn't really meaningful, so hide it
6262
#' ggplot(mtcars, aes(x = mpg)) + geom_dotplot(binwidth = 1.5) +
63-
#' scale_y_continuous(name = "", breaks = NA)
63+
#' scale_y_continuous(name = "", breaks = NULL)
6464
#'
6565
#' # Overlap dots vertically
6666
#' ggplot(mtcars, aes(x = mpg)) + geom_dotplot(binwidth = 1.5, stackratio = .7)
@@ -95,7 +95,7 @@
9595
#'
9696
#' ggplot(mtcars, aes(x = 1, y = mpg, fill = factor(cyl))) +
9797
#' geom_dotplot(binaxis = "y", stackgroups = TRUE, binwidth = 1, method = "histodot")
98-
#'
98+
#'
9999
#' # Use qplot instead
100100
#' qplot(mpg, data = mtcars, geom = "dotplot")
101101
#'

R/scale-gradient2.r

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
#' d + scale_colour_gradient2(midpoint=mean(diamonds$price / diamonds$carat))
4646
#'
4747
#' # Fill gradients work much the same way
48-
#' p <- qplot(letters[1:5], 1:5, fill= c(-3, 3, 5, 2, -2), geom="bar")
48+
#' p <- qplot(letters[1:5], 1:5, fill= c(-3, 3, 5, 2, -2), geom = "bar",
49+
#' stat = "identity")
4950
#' p + scale_fill_gradient2("fill")
5051
#' # Note how positive and negative values of the same magnitude
5152
#' # have similar intensity

R/scale-size.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#' # Map area, instead of width/radius
1717
#' # Perceptually, this is a little better
1818
#' p + scale_size_area()
19-
#' p + scale_size_area(range = c(1, 25))
19+
#' p + scale_size_area(max_size = 25)
2020
#'
2121
#' # Also works with factors, but not a terribly good
2222
#' # idea, unless your factor is ordered, as in this example

R/stat-sum.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#' # by overall proportion
2525
#' d + stat_sum(aes(group = 1))
2626
#' d + stat_sum(aes(group = 1)) + scale_size(range = c(3, 10))
27-
#' d + stat_sum(aes(group = 1)) + scale_size_area(range = c(3, 10))
27+
#' d + stat_sum(aes(group = 1)) + scale_size_area(max_size = 10)
2828
#'
2929
#' # by cut
3030
#' d + stat_sum(aes(group = cut))

man/annotation_custom.Rd

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,13 @@ Inf values can be used to fill the full plot panel (see examples).
3434
# Dummy plot
3535
base <- qplot(1:10, 1:10, geom = "blank") + theme_bw()
3636
# Adding a table
37-
\donttest{
38-
require(gridExtra)
37+
\donttest{if (require(gridExtra)) {
3938
base + annotation_custom(grob = tableGrob(head(iris[ ,1:3])),
4039
xmin = 3, xmax = 6, ymin = 2, ymax = 8)
4140
# full panel
4241
base + annotation_custom(grob = roundrectGrob(),
4342
xmin = -Inf, xmax = Inf, ymin = -Inf, ymax = Inf)
44-
}
43+
}}
4544
# Inset plot
4645
g <- ggplotGrob(qplot(1, 1) +
4746
theme(plot.background = element_rect(colour = "black")))

man/geom_dotplot.Rd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ ggplot(mtcars, aes(x = mpg)) +
9393
9494
# y axis isn't really meaningful, so hide it
9595
ggplot(mtcars, aes(x = mpg)) + geom_dotplot(binwidth = 1.5) +
96-
scale_y_continuous(name = "", breaks = NA)
96+
scale_y_continuous(name = "", breaks = NULL)
9797

9898
# Overlap dots vertically
9999
ggplot(mtcars, aes(x = mpg)) + geom_dotplot(binwidth = 1.5, stackratio = .7)

man/labeller.Rd

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,18 @@ or ``unused argument (variable)'', matching the method's arguments does not
3333
work as expected; make a wrapper function.
3434
}
3535
\examples{
36-
data(mpg)
37-
36+
\donttest{
3837
p1 <- ggplot(mpg, aes(cty, hwy)) + geom_point()
39-
40-
4138
p1 + facet_grid(cyl ~ class, labeller=label_both)
42-
4339
p1 + facet_grid(cyl ~ class, labeller=labeller(cyl=label_both))
4440
4541
ggplot(mtcars, aes(x = mpg, y = wt)) + geom_point() +
4642
facet_grid(vs + am ~ gear, margins=TRUE,
4743
labeller=labeller(vs=label_both, am=label_both))
4844
49-
50-
51-
data(msleep)
5245
capitalize <- function(string) {
5346
substr(string, 1, 1) <- toupper(substr(string, 1, 1))
54-
string
47+
string
5548
}
5649
conservation_status <- c('cd'='Conservation Dependent',
5750
'en'='Endangered',
@@ -61,20 +54,21 @@ conservation_status <- c('cd'='Conservation Dependent',
6154
'domesticated'='Domesticated')
6255
## Source: http://en.wikipedia.org/wiki/Uncyclopedia:Conservation_status
6356
64-
p2 <- ggplot(msleep, aes(x=sleep_total, y=awake)) + geom_point() +
65-
p2 + facet_grid(vore ~ conservation, labeller=labeller(vore=capitalize))
57+
p2 <- ggplot(msleep, aes(x=sleep_total, y=awake)) + geom_point()
58+
p2 + facet_grid(vore ~ conservation, labeller = labeller(vore = capitalize))
6659
6760
p2 + facet_grid(vore ~ conservation,
68-
labeller=labeller(vore=capitalize, conservation=conservation_status ))
61+
labeller=labeller(vore = capitalize, conservation = conservation_status ))
6962
7063
# We could of course have renamed the levels;
7164
# then we can apply another nifty function:
72-
library(plyr)
73-
msleep$conservation2 <- revalue(msleep$conservation, conservation_status)
65+
msleep$conservation2 <- plyr::revalue(msleep$conservation, conservation_status)
7466
75-
p2 + facet_grid(vore ~ conservation2, labeller=labeller(vore=capitalize))
76-
77-
p2 + facet_grid(vore ~ conservation2,
78-
labeller=labeller(conservation2=label_wrap_gen(10) ))
67+
p2 \%+\% msleep +
68+
facet_grid(vore ~ conservation2, labeller = labeller(vore = capitalize))
69+
p2 \%+\% msleep +
70+
facet_grid(vore ~ conservation2, labeller = labeller(conservation2 =
71+
label_wrap_gen(10)))
72+
}
7973
}
8074

man/scale_gradient2.Rd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ d + scale_colour_gradient2(mid=muted("green"), high="white", low="white")
7777
d + scale_colour_gradient2(midpoint=mean(diamonds$price / diamonds$carat))
7878

7979
# Fill gradients work much the same way
80-
p <- qplot(letters[1:5], 1:5, fill= c(-3, 3, 5, 2, -2), geom="bar")
80+
p <- qplot(letters[1:5], 1:5, fill= c(-3, 3, 5, 2, -2), geom = "bar",
81+
stat = "identity")
8182
p + scale_fill_gradient2("fill")
8283
# Note how positive and negative values of the same magnitude
8384
# have similar intensity

man/scale_size.Rd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ p + scale_size(range = c(1, 2))
3434
# Map area, instead of width/radius
3535
# Perceptually, this is a little better
3636
p + scale_size_area()
37-
p + scale_size_area(range = c(1, 25))
37+
p + scale_size_area(max_size = 25)
3838

3939
# Also works with factors, but not a terribly good
4040
# idea, unless your factor is ordered, as in this example

man/stat_sum.Rd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ d + stat_sum()
5050
# by overall proportion
5151
d + stat_sum(aes(group = 1))
5252
d + stat_sum(aes(group = 1)) + scale_size(range = c(3, 10))
53-
d + stat_sum(aes(group = 1)) + scale_size_area(range = c(3, 10))
53+
d + stat_sum(aes(group = 1)) + scale_size_area(max_size = 10)
5454

5555
# by cut
5656
d + stat_sum(aes(group = cut))

0 commit comments

Comments
 (0)