Skip to content
This repository
Browse code

Re-roxygenize

  • Loading branch information...
commit 6661a5b312810f719556cc422db4d0d29e2ad243 1 parent 252b108
Winston Chang wch authored
5 NAMESPACE
... ... @@ -1,4 +1,6 @@
1 1 export("%+%")
  2 +export("%+replace%")
  3 +export("+.theme")
2 4 export(aes_all)
3 5 export(aes_auto)
4 6 export(aes_string)
@@ -11,6 +13,7 @@ export(annotation_raster)
11 13 export(autoplot)
12 14 export(benchplot)
13 15 export(borders)
  16 +export(calc_element)
14 17 export(continuous_scale)
15 18 export(coord_cartesian)
16 19 export(coord_equal)
@@ -211,6 +214,7 @@ export(theme_segment)
211 214 export(theme_set)
212 215 export(theme_text)
213 216 export(theme_update)
  217 +export(theme)
214 218 export(update_element)
215 219 export(update_geom_defaults)
216 220 export(update_labels)
@@ -231,7 +235,6 @@ importFrom(MASS,kde2d)
231 235 S3method("[",uneval)
232 236 S3method("+",ggplot)
233 237 S3method("+",theme)
234   -S3method("|",theme)
235 238 S3method(as.character,uneval)
236 239 S3method(autoplot,default)
237 240 S3method(cbind,gtable)
13 man/add_theme.Rd
... ... @@ -0,0 +1,13 @@
  1 +\name{add_theme}
  2 +\alias{add_theme}
  3 +\title{Modify properties of an element in a theme object}
  4 +\usage{
  5 + add_theme(t1, t2)
  6 +}
  7 +\description{
  8 + Modify properties of an element in a theme object
  9 +}
  10 +\seealso{
  11 + +.theme
  12 +}
  13 +
2  man/annotation_custom.Rd
@@ -47,7 +47,7 @@ base + annotation_custom(grob = roundrectGrob(),
47 47 }
48 48 # Inset plot
49 49 g <- ggplotGrob(qplot(1, 1) +
50   - opts(plot.background = theme_rect(col = "black")))
  50 + theme(plot.background = element_rect(col = "black")))
51 51 base +
52 52 annotation_custom(grob = g, xmin = 1, xmax = 10, ymin = 8, ymax = 10)
53 53 }
4 man/annotation_logticks.Rd
@@ -54,14 +54,14 @@ a + annotation_logticks(sides = "lr") # Log ticks for y, on left and right
54 54 a + annotation_logticks(sides = "trbl") # All four sides
55 55
56 56 # Hide the minor grid lines because they don't align with the ticks
57   -a + annotation_logticks(sides = "trbl") + opts(panel.grid.minor = theme_blank())
  57 +a + annotation_logticks(sides = "trbl") + theme(panel.grid.minor = element_blank())
58 58
59 59
60 60 # Another way to get the same results as 'a' above: log-transform the data before
61 61 b <- ggplot(Animals, aes(x = log10(body), y = log10(brain))) + geom_point() +
62 62 scale_x_continuous(name = "body", labels = math_format(10^.x)) +
63 63 scale_y_continuous(name = "brain", labels = math_format(10^.x)) +
64   - theme_bw()+ opts(panel.grid.minor = theme_blank())
  64 + theme_bw()+ theme(panel.grid.minor = element_blank())
65 65
66 66 b + annotation_logticks()
67 67
17 man/calc_element.Rd
... ... @@ -0,0 +1,17 @@
  1 +\name{calc_element}
  2 +\alias{calc_element}
  3 +\title{Calculate the element properties, by inheriting properties from its parents}
  4 +\usage{
  5 + calc_element(element, theme)
  6 +}
  7 +\arguments{
  8 + \item{element}{The name of the theme element to
  9 + calculate}
  10 +
  11 + \item{theme}{A theme object (like theme_grey())}
  12 +}
  13 +\description{
  14 + Calculate the element properties, by inheriting
  15 + properties from its parents
  16 +}
  17 +
2  man/coord_polar.Rd
@@ -49,7 +49,7 @@ ggplot(df, aes(x = "", y = value, fill = variable)) +
49 49 geom_bar(width = 1) +
50 50 scale_fill_manual(values = c("red", "yellow")) +
51 51 coord_polar("y", start=pi / 3) +
52   - opts(title = "Pac man")
  52 + theme(title = "Pac man")
53 53
54 54 # Windrose + doughnut plot
55 55 movies$rrating <- cut_interval(movies$rating, length = 1)
2  man/facet_grid.Rd
@@ -141,7 +141,7 @@ mpg <- within(mpg, {
141 141 model <- reorder(model, cty)
142 142 manufacturer <- reorder(manufacturer, cty)
143 143 })
144   -last_plot() \%+\% mpg + opts(strip.text.y = theme_text())
  144 +last_plot() \%+\% mpg + theme(strip.text.y = element_text())
145 145
146 146 # Use as.table to to control direction of horizontal facets, TRUE by default
147 147 h <- ggplot(mtcars, aes(x = mpg, y = wt)) + geom_point()
4 man/facet_wrap.Rd
@@ -38,7 +38,7 @@
38 38 \examples{
39 39 \donttest{
40 40 d <- ggplot(diamonds, aes(carat, price, fill = ..density..)) +
41   - xlim(0, 2) + stat_binhex(na.rm = TRUE) + opts(aspect.ratio = 1)
  41 + xlim(0, 2) + stat_binhex(na.rm = TRUE) + theme(aspect.ratio = 1)
42 42 d + facet_wrap(~ color)
43 43 d + facet_wrap(~ color, ncol = 1)
44 44 d + facet_wrap(~ color, ncol = 4)
@@ -54,7 +54,7 @@ d + facet_wrap(~ color, nrow = 3)
54 54 diamonds$color <- factor(diamonds$color, levels = c("G", "J", "D", "E", "I", "F", "H"))
55 55 # Repeat first example with new order
56 56 d <- ggplot(diamonds, aes(carat, price, fill = ..density..)) +
57   -xlim(0, 2) + stat_binhex(na.rm = TRUE) + opts(aspect.ratio = 1)
  57 +xlim(0, 2) + stat_binhex(na.rm = TRUE) + theme(aspect.ratio = 1)
58 58 d + facet_wrap(~ color)
59 59
60 60 # You can choose to keep the scales constant across all panels
14 man/guide_colourbar.Rd
@@ -27,12 +27,12 @@
27 27 \item{barwidth}{A numeric or a unit object specifying the
28 28 width of the colorbar. Default value is
29 29 \code{legend.key.width} or \code{legend.key.size} in
30   - \code{\link{opts}} or theme.}
  30 + \code{\link{theme}} or theme.}
31 31
32 32 \item{barheight}{A numeric or a unit object specifying
33 33 the height of the colorbar. Default value is
34 34 \code{legend.key.height} or \code{legend.key.size} in
35   - \code{\link{opts}} or theme.}
  35 + \code{\link{theme}} or theme.}
36 36
37 37 \item{nbin}{A numeric specifying the number of bins for
38 38 drawing colorbar. A smoother colorbar for a larger
@@ -78,9 +78,9 @@
78 78 guide), or "right."}
79 79
80 80 \item{title.theme}{A theme object for rendering the title
81   - text. Usually the object of \code{\link{theme_text}} is
  81 + text. Usually the object of \code{\link{element_text}} is
82 82 expected. By default, the theme is specified by
83   - \code{legend.title} in \code{\link{opts}} or theme.}
  83 + \code{legend.title} in \code{\link{theme}} or theme.}
84 84
85 85 \item{title.hjust}{A number specifying horizontal
86 86 justification of the title text.}
@@ -97,9 +97,9 @@
97 97 vertical gudie).}
98 98
99 99 \item{label.theme}{A theme object for rendering the label
100   - text. Usually the object of \code{\link{theme_text}} is
  100 + text. Usually the object of \code{\link{element_text}} is
101 101 expected. By default, the theme is specified by
102   - \code{legend.text} in \code{\link{opts}} or theme.}
  102 + \code{legend.text} in \code{\link{theme}} or theme.}
103 103
104 104 \item{label.hjust}{A numeric specifying horizontal
105 105 justification of the label text.}
@@ -153,7 +153,7 @@ p1 + guides(fill = guide_colorbar(ticks = FALSE))
153 153 p1 + guides(fill = guide_colorbar(label.position = "left"))
154 154
155 155 # label theme
156   -p1 + guides(fill = guide_colorbar(label.theme = theme_text(col="blue")))
  156 +p1 + guides(fill = guide_colorbar(label.theme = element_text(col="blue")))
157 157
158 158 # small number of bins
159 159 p1 + guides(fill = guide_colorbar(nbin = 3))
18 man/guide_legend.Rd
@@ -25,9 +25,9 @@
25 25 guide), or "right."}
26 26
27 27 \item{title.theme}{A theme object for rendering the title
28   - text. Usually the object of \code{\link{theme_text}} is
  28 + text. Usually the object of \code{\link{element_text}} is
29 29 expected. By default, the theme is specified by
30   - \code{legend.title} in \code{\link{opts}} or theme.}
  30 + \code{legend.title} in \code{\link{theme}} or theme.}
31 31
32 32 \item{title.hjust}{A number specifying horizontal
33 33 justification of the title text.}
@@ -44,9 +44,9 @@
44 44 vertical gudie).}
45 45
46 46 \item{label.theme}{A theme object for rendering the label
47   - text. Usually the object of \code{\link{theme_text}} is
  47 + text. Usually the object of \code{\link{element_text}} is
48 48 expected. By default, the theme is specified by
49   - \code{legend.text} in \code{\link{opts}} or theme.}
  49 + \code{legend.text} in \code{\link{theme}} or theme.}
50 50
51 51 \item{label.hjust}{A numeric specifying horizontal
52 52 justification of the label text.}
@@ -57,12 +57,12 @@
57 57 \item{keywidth}{A numeric or a unit object specifying the
58 58 width of the legend key. Default value is
59 59 \code{legend.key.width} or \code{legend.key.size} in
60   - \code{\link{opts}} or theme.}
  60 + \code{\link{theme}} or theme.}
61 61
62 62 \item{keyheight}{A numeric or a unit object specifying
63 63 the height of the legend key. Default value is
64 64 \code{legend.key.height} or \code{legend.key.size} in
65   - \code{\link{opts}} or theme.}
  65 + \code{\link{theme}} or theme.}
66 66
67 67 \item{direction}{A character string indicating the
68 68 direction of the guide. One of "horizontal" or
@@ -128,9 +128,9 @@ p1 + guides(fill = guide_legend(keywidth = 3, keyheight = 1))
128 128 # title position
129 129 p1 + guides(fill = guide_legend(title = "LEFT", title.position = "left"))
130 130
131   -# title text styles via theme_text
  131 +# title text styles via element_text
132 132 p1 + guides(fill = guide_legend(
133   - title.theme = theme_text(size=15, face="italic", col="red", angle=45)))
  133 + title.theme = element_text(size=15, face="italic", col="red", angle=45)))
134 134
135 135 # label position
136 136 p1 + guides(fill = guide_legend(label.position = "bottom"))
@@ -140,7 +140,7 @@ p1 + scale_fill_continuous(breaks = c(5, 10, 15),
140 140 labels = paste("long", c(5, 10, 15)),
141 141 guide = guide_legend(direction = "horizontal", title.position = "top",
142 142 label.position="bottom", label.hjust = 0.5, label.vjust = 0.5,
143   - label.theme = theme_text(angle = 90)))
  143 + label.theme = element_text(angle = 90)))
144 144
145 145 # Set aesthetic of legend key
146 146
4 man/guides.Rd
@@ -45,11 +45,11 @@ p + guides(colour = guide_legend("title"), size = guide_legend("title"),
45 45 g <- guide_legend("title")
46 46 p + guides(colour = g, size = g, shape = g)
47 47
48   -p + opts(legend.position = "bottom")
  48 +p + theme(legend.position = "bottom")
49 49
50 50 # position of guides
51 51
52   -p + opts(legend.position = "bottom", legend.box = "horizontal")
  52 +p + theme(legend.position = "bottom", legend.box = "horizontal")
53 53 }
54 54 }
55 55 \seealso{
144 man/opts.Rd
... ... @@ -1,149 +1,11 @@
1 1 \name{opts}
2 2 \alias{opts}
3   -\title{Set options/theme elements for a single plot}
  3 +\title{Build a theme (or partial theme) from theme elements}
4 4 \usage{
5 5 opts(...)
6 6 }
7   -\arguments{
8   - \item{...}{a list of element name, element pairings that
9   - modify the existing theme.}
10   -}
11 7 \description{
12   - Use this function if you want to modify a few theme
13   - settings for a single plot.
14   -}
15   -\section{Theme elements}{
16   - The individual theme elements are:
17   -
18   - \tabular{ll}{ axis.line \tab line along axis \cr
19   - axis.title.x \tab x axis label \cr axis.title.y \tab y
20   - axis label \cr axis.ticks \tab axis tick marks \cr
21   - axis.ticks.length \tab tick mark length \cr
22   - axis.ticks.margin \tab tick mark margin spacing \cr
23   - axis.text.x \tab horizontal tick labels \cr axis.text.y
24   - \tab vertical tick labels \cr legend.background \tab
25   - background of legend \cr legend.margin \tab extra space
26   - added around legend (both width or height depending on
27   - orientation of legend) \cr legend.key \tab background
28   - underneath legend keys \cr legend.key.size \tab key
29   - background size \cr legend.key.height \tab key background
30   - height \cr legend.key.width \tab key background width \cr
31   - legend.text \tab legend labels \cr legend.text.align \tab
32   - alignment of legend labels \cr legend.title \tab legend
33   - name \cr legend.title.align \tab alignment of legend
34   - title \cr legend.position \tab A string or numeric vector
35   - specifying the position of guides (legends). Possible
36   - values are: "left", "right", "bottom", "top", and
37   - two-element numeric vector. \cr legend.justification \tab
38   - alignment of legend \cr legend.direction \tab horizontal
39   - or vertical \cr legend.box \tab A string specifying the
40   - direction of multiple guides. Possible string values are:
41   - "horizontal" and "vertical". \cr panel.background \tab
42   - background of panel \cr panel.border \tab border around
43   - panel \cr panel.margin \tab margin around facet panels
44   - \cr panel.grid.major \tab major grid lines \cr
45   - panel.grid.minor \tab minor grid lines \cr
46   - plot.background \tab background of the entire plot \cr
47   - plot.title \tab plot title (text appearance) \cr
48   - plot.margin \tab plot margins \cr strip.background \tab
49   - background of facet labels \cr strip.text.x \tab text for
50   - horizontal strips \cr strip.text.y \tab text for vertical
51   - strips \cr title \tab A string containing the title of
52   - the plot \cr }
53   -}
54   -\examples{
55   -\donttest{
56   -p <- qplot(mpg, wt, data = mtcars)
57   -p
58   -p + opts(panel_background = theme_rect(colour = "pink"))
59   -p + theme_bw()
60   -
61   -# Scatter plot of gas mileage by vehicle weight
62   -p <- ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point()
63   -# Calculate slope and intercept of line of best fit
64   -coef(lm(mpg ~ wt, data = mtcars))
65   -p + geom_abline(intercept = 37, slope = -5)
66   -# Calculate correlation coefficient
67   -with(mtcars, cor(wt, mpg, use = "everything", method = "pearson"))
68   -#annotate the plot
69   -p + geom_abline(intercept = 37, slope = -5) +
70   -geom_text(data = data.frame(), aes(4.5, 30, label = "Pearson-R = -.87"))
71   -
72   -# Change the axis labels
73   -# Original plot
74   -p
75   -p + xlab("Vehicle Weight") + ylab("Miles per Gallon")
76   -# Or
77   -p + labs(x = "Vehicle Weight", y = "Miles per Gallon")
78   -
79   -# Add a title to the plot
80   -p + opts(title = "Vehicle Weight-Gas Mileage Relationship")
81   -# Change title appearance
82   -p <- p + opts(title = "Vehicle Weight-Gas Mileage Relationship")
83   -p + opts(plot.title = theme_text(size = 20))
84   -p + opts(plot.title = theme_text(size = 20, colour = "Blue"))
85   -
86   -# Changing plot look with themes
87   -DF <- data.frame(x = rnorm(400))
88   -m <- ggplot(DF, aes(x = x)) + geom_histogram()
89   -#default is theme_grey()
90   -m
91   -# Compare with
92   -m + theme_bw()
93   -
94   -# Manipulate Axis Attributes
95   -library(grid) # for unit
96   -m + opts(axis.line = theme_segment())
97   -m + opts(axis.line = theme_segment(colour = "red", linetype = "dotted"))
98   -m + opts(axis.text.x = theme_text(colour = "blue"))
99   -m + opts(axis.text.y = theme_blank())
100   -m + opts(axis.ticks = theme_segment(size = 2))
101   -m + opts(axis.title.y = theme_text(size = 20, angle = 90))
102   -m + opts(axis.title.x = theme_blank())
103   -m + opts(axis.ticks.length = unit(.85, "cm"))
104   -
105   -# Legend Attributes
106   -z <- ggplot(mtcars, aes(wt, mpg, colour = factor(cyl))) + geom_point()
107   -z
108   -z + opts(legend.position = "none")
109   -z + opts(legend.position = "bottom")
110   -# Or use relative coordinates between 0 and 1
111   -z + opts(legend.position = c(.5, .5))
112   -z + opts(legend.background = theme_rect())
113   -# Legend margin controls extra space around outside of legend:
114   -z + opts(legend.background = theme_rect(), legend.margin = unit(1, "cm"))
115   -z + opts(legend.background = theme_rect(), legend.margin = unit(0, "cm"))
116   -# Or to just the keys
117   -z + opts(legend.key = theme_rect())
118   -z + opts(legend.key = theme_rect(fill = "yellow"))
119   -z + opts(legend.key.size = unit(2.5, "cm"))
120   -z + opts(legend.text = theme_text(size = 20, colour = "red", angle = 45))
121   -z + opts(legend.title = theme_text(face = "italic"))
122   -
123   -# To change the title of the legend use the name argument
124   -# in one of the scale options
125   -z + scale_colour_brewer(name = "My Legend")
126   -z + scale_colour_grey(name = "Number of \\nCylinders")
127   -
128   -# Panel and Plot Attributes
129   -z + opts(panel.background = theme_rect())
130   -z + opts(panel.background = theme_rect(fill = "black"))
131   -z + opts(panel.border = theme_rect(linetype = "dashed"))
132   -z + opts(panel.grid.major = theme_line(colour = "blue"))
133   -z + opts(panel.grid.minor = theme_line(colour = "red", linetype = "dotted"))
134   -z + opts(panel.grid.major = theme_line(size = 2))
135   -z + opts(plot.background = theme_rect())
136   -z + opts(plot.background = theme_rect(fill = "grey"))
137   -
138   -# Faceting Attributes
139   -set.seed(4940)
140   -dsmall <- diamonds[sample(nrow(diamonds), 1000), ]
141   -k <- ggplot(dsmall, aes(carat, ..density..)) + geom_histogram(binwidth = 0.2) +
142   -facet_grid(. ~ cut)
143   -k + opts(strip.background = theme_rect(colour = "purple", fill = "pink", size = 3, linetype = "dashed"))
144   -k + opts(strip.text.x = theme_text(colour = "red", angle = 45, size = 10, hjust = 0.5, vjust = 0.5))
145   -k + opts(panel.margin = unit(5, "lines"))
146   -k + opts(panel.margin = unit(0, "lines"))
147   -}
  8 + \code{opts} is deprecated. See the \code{\link{theme}}
  9 + function.
148 10 }
149 11
2  man/scale_date.Rd
@@ -43,7 +43,7 @@ df <- data.frame(
43 43 price = runif(50)
44 44 )
45 45 df <- df[order(df$date), ]
46   -dt <- qplot(date, price, data=df, geom="line") + opts(aspect.ratio = 1/4)
  46 +dt <- qplot(date, price, data=df, geom="line") + theme(aspect.ratio = 1/4)
47 47
48 48 # We can control the format of the labels, and the frequency of
49 49 # the major and minor tickmarks. See ?format.Date and ?seq.Date
26 man/theme-add.Rd
... ... @@ -1,18 +1,36 @@
1 1 \name{+.theme}
  2 +\alias{\%+replace\%}
2 3 \alias{+.theme}
3   -\title{Modify a theme object}
  4 +\title{Modify elements in a theme object}
4 5 \usage{
5 6 +.theme(e1, e2)
  7 +
  8 + %+replace%(e1, e2)
6 9 }
7 10 \arguments{
8 11 \item{e1}{theme object}
9 12
10   - \item{e2}{theme object to add}
  13 + \item{e2}{theme object to use for updating e1}
11 14 }
12 15 \description{
13   - Modify a theme object
  16 + The \code{+} operator and the \code{\%+replace\%} can be
  17 + used to modify elements in themes.
  18 +}
  19 +\details{
  20 + The \code{+} operator completely replaces elements with
  21 + elements from e2.
  22 +
  23 + In contrast, the \code{\%+replace\%} operator does not
  24 + replace the entire element; it only updates element
  25 + properties which are present (not NULL) in the second
  26 + object.
14 27 }
15 28 \examples{
16   -mytheme <- theme_grey() + opts(axis.title.x = element_text(family = "Times"))
  29 +# Compare these results
  30 +add_el <- theme_grey() + theme(text = element_text(family = "Times"))
  31 +rep_el <- theme_grey() \%+replace\% theme(text = element_text(family = "Times"))
  32 +
  33 +add_el$text
  34 +rep_el$text
17 35 }
18 36
26 man/theme-element-update.Rd
... ... @@ -1,26 +0,0 @@
1   -\name{|.theme}
2   -\alias{|.theme}
3   -\title{Modify properties of an element in a theme object}
4   -\usage{
5   - |.theme(t1, t2)
6   -}
7   -\arguments{
8   - \item{e1}{theme object}
9   -
10   - \item{e2}{theme object to use for updating}
11   -}
12   -\description{
13   - In contrast with the \code{+.theme} operator, this
14   - operator does not replace the entire element; it only
15   - updates element properties which are present (not NULL)
16   - in the second object.
17   -}
18   -\examples{
19   -# Compare these results
20   -mod_el <- theme_grey() | opts(text = element_text(family = "Times"))
21   -add_el <- theme_grey() + opts(text = element_text(family = "Times"))
22   -
23   -mod_el$text
24   -add_el$text
25   -}
26   -
149 man/theme.Rd
... ... @@ -0,0 +1,149 @@
  1 +\name{theme}
  2 +\alias{theme}
  3 +\title{Set options/theme elements for a single plot}
  4 +\usage{
  5 + theme(...)
  6 +}
  7 +\arguments{
  8 + \item{...}{a list of element name, element pairings that
  9 + modify the existing theme.}
  10 +}
  11 +\description{
  12 + Use this function if you want to modify a few theme
  13 + settings for a single plot.
  14 +}
  15 +\section{Theme elements}{
  16 + The individual theme elements are:
  17 +
  18 + \tabular{ll}{ axis.line \tab line along axis \cr
  19 + axis.title.x \tab x axis label \cr axis.title.y \tab y
  20 + axis label \cr axis.ticks \tab axis tick marks \cr
  21 + axis.ticks.length \tab tick mark length \cr
  22 + axis.ticks.margin \tab tick mark margin spacing \cr
  23 + axis.text.x \tab horizontal tick labels \cr axis.text.y
  24 + \tab vertical tick labels \cr legend.background \tab
  25 + background of legend \cr legend.margin \tab extra space
  26 + added around legend (both width or height depending on
  27 + orientation of legend) \cr legend.key \tab background
  28 + underneath legend keys \cr legend.key.size \tab key
  29 + background size \cr legend.key.height \tab key background
  30 + height \cr legend.key.width \tab key background width \cr
  31 + legend.text \tab legend labels \cr legend.text.align \tab
  32 + alignment of legend labels \cr legend.title \tab legend
  33 + name \cr legend.title.align \tab alignment of legend
  34 + title \cr legend.position \tab A string or numeric vector
  35 + specifying the position of guides (legends). Possible
  36 + values are: "left", "right", "bottom", "top", and
  37 + two-element numeric vector. \cr legend.justification \tab
  38 + alignment of legend \cr legend.direction \tab horizontal
  39 + or vertical \cr legend.box \tab A string specifying the
  40 + direction of multiple guides. Possible string values are:
  41 + "horizontal" and "vertical". \cr panel.background \tab
  42 + background of panel \cr panel.border \tab border around
  43 + panel \cr panel.margin \tab margin around facet panels
  44 + \cr panel.grid.major \tab major grid lines \cr
  45 + panel.grid.minor \tab minor grid lines \cr
  46 + plot.background \tab background of the entire plot \cr
  47 + plot.title \tab plot title (text appearance) \cr
  48 + plot.margin \tab plot margins \cr strip.background \tab
  49 + background of facet labels \cr strip.text.x \tab text for
  50 + horizontal strips \cr strip.text.y \tab text for vertical
  51 + strips \cr title \tab A string containing the title of
  52 + the plot \cr }
  53 +}
  54 +\examples{
  55 +\donttest{
  56 +p <- qplot(mpg, wt, data = mtcars)
  57 +p
  58 +p + theme(panel_background = element_rect(colour = "pink"))
  59 +p + theme_bw()
  60 +
  61 +# Scatter plot of gas mileage by vehicle weight
  62 +p <- ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point()
  63 +# Calculate slope and intercept of line of best fit
  64 +coef(lm(mpg ~ wt, data = mtcars))
  65 +p + geom_abline(intercept = 37, slope = -5)
  66 +# Calculate correlation coefficient
  67 +with(mtcars, cor(wt, mpg, use = "everything", method = "pearson"))
  68 +#annotate the plot
  69 +p + geom_abline(intercept = 37, slope = -5) +
  70 +geom_text(data = data.frame(), aes(4.5, 30, label = "Pearson-R = -.87"))
  71 +
  72 +# Change the axis labels
  73 +# Original plot
  74 +p
  75 +p + xlab("Vehicle Weight") + ylab("Miles per Gallon")
  76 +# Or
  77 +p + labs(x = "Vehicle Weight", y = "Miles per Gallon")
  78 +
  79 +# Add a title to the plot
  80 +p + theme(title = "Vehicle Weight-Gas Mileage Relationship")
  81 +# Change title appearance
  82 +p <- p + theme(title = "Vehicle Weight-Gas Mileage Relationship")
  83 +p + theme(plot.title = element_text(size = 20))
  84 +p + theme(plot.title = element_text(size = 20, colour = "Blue"))
  85 +
  86 +# Changing plot look with themes
  87 +DF <- data.frame(x = rnorm(400))
  88 +m <- ggplot(DF, aes(x = x)) + geom_histogram()
  89 +#default is theme_grey()
  90 +m
  91 +# Compare with
  92 +m + theme_bw()
  93 +
  94 +# Manipulate Axis Attributes
  95 +library(grid) # for unit
  96 +m + theme(axis.line = element_segment())
  97 +m + theme(axis.line = element_segment(colour = "red", linetype = "dotted"))
  98 +m + theme(axis.text.x = element_text(colour = "blue"))
  99 +m + theme(axis.text.y = element_blank())
  100 +m + theme(axis.ticks = element_segment(size = 2))
  101 +m + theme(axis.title.y = element_text(size = 20, angle = 90))
  102 +m + theme(axis.title.x = element_blank())
  103 +m + theme(axis.ticks.length = unit(.85, "cm"))
  104 +
  105 +# Legend Attributes
  106 +z <- ggplot(mtcars, aes(wt, mpg, colour = factor(cyl))) + geom_point()
  107 +z
  108 +z + theme(legend.position = "none")
  109 +z + theme(legend.position = "bottom")
  110 +# Or use relative coordinates between 0 and 1
  111 +z + theme(legend.position = c(.5, .5))
  112 +z + theme(legend.background = element_rect())
  113 +# Legend margin controls extra space around outside of legend:
  114 +z + theme(legend.background = element_rect(), legend.margin = unit(1, "cm"))
  115 +z + theme(legend.background = element_rect(), legend.margin = unit(0, "cm"))
  116 +# Or to just the keys
  117 +z + theme(legend.key = element_rect())
  118 +z + theme(legend.key = element_rect(fill = "yellow"))
  119 +z + theme(legend.key.size = unit(2.5, "cm"))
  120 +z + theme(legend.text = element_text(size = 20, colour = "red", angle = 45))
  121 +z + theme(legend.title = element_text(face = "italic"))
  122 +
  123 +# To change the title of the legend use the name argument
  124 +# in one of the scale options
  125 +z + scale_colour_brewer(name = "My Legend")
  126 +z + scale_colour_grey(name = "Number of \\nCylinders")
  127 +
  128 +# Panel and Plot Attributes
  129 +z + theme(panel.background = element_rect())
  130 +z + theme(panel.background = element_rect(fill = "black"))
  131 +z + theme(panel.border = element_rect(linetype = "dashed"))
  132 +z + theme(panel.grid.major = element_line(colour = "blue"))
  133 +z + theme(panel.grid.minor = element_line(colour = "red", linetype = "dotted"))
  134 +z + theme(panel.grid.major = element_line(size = 2))
  135 +z + theme(plot.background = element_rect())
  136 +z + theme(plot.background = element_rect(fill = "grey"))
  137 +
  138 +# Faceting Attributes
  139 +set.seed(4940)
  140 +dsmall <- diamonds[sample(nrow(diamonds), 1000), ]
  141 +k <- ggplot(dsmall, aes(carat, ..density..)) + geom_histogram(binwidth = 0.2) +
  142 +facet_grid(. ~ cut)
  143 +k + theme(strip.background = element_rect(colour = "purple", fill = "pink", size = 3, linetype = "dashed"))
  144 +k + theme(strip.text.x = element_text(colour = "red", angle = 45, size = 10, hjust = 0.5, vjust = 0.5))
  145 +k + theme(panel.margin = unit(5, "lines"))
  146 +k + theme(panel.margin = unit(0, "lines"))
  147 +}
  148 +}
  149 +
4 man/theme_update.Rd
@@ -33,8 +33,8 @@ theme_set(old)
33 33 theme_get()
34 34
35 35 qplot(mpg, wt, data=mtcars, colour=mpg) +
36   - opts(legend.position=c(0.95, 0.95), legend.justification = c(1, 1))
  36 + theme(legend.position=c(0.95, 0.95), legend.justification = c(1, 1))
37 37 last_plot() +
38   - opts(legend.background = element_rect(fill = "white", col="white", size = 3))
  38 + theme(legend.background = element_rect(fill = "white", col="white", size = 3))
39 39 }
40 40
6 man/translate_qplot_base.Rd
@@ -111,7 +111,7 @@ last_plot() + geom_line()
111 111
112 112 # In ggplot2, the appearance of legends and axes is controlled by the scales.
113 113 # Axes are produced by the x and y scales, while all other scales produce legends.
114   -# See ?opts for help changing the appearance of axes and legends.
  114 +# See ?theme for help changing the appearance of axes and legends.
115 115 # The appearance of grid lines is controlled by the grid.major and grid.minor
116 116 # theme options, and their position by the breaks of the x and y scales.
117 117
@@ -142,8 +142,8 @@ last_plot() + scale_colour_gradientn(colours = terrain.colors(7))
142 142 # in the defaults of the geoms and scales. The appearance plot border drawn
143 143 # by box() can be controlled in a similar way by the panel.background and
144 144 # plot.background theme elements. Instead of using title(), the plot title is
145   -# set with the title option. See ?opts for more theme elements.
146   -last_plot() + opts(title = "My Plot Title")
  145 +# set with the title option. See ?theme for more theme elements.
  146 +last_plot() + theme(title = "My Plot Title")
147 147 }
148 148 }
149 149
4 man/translate_qplot_ggplot.Rd
@@ -77,8 +77,8 @@
77 77 # Plot options
78 78
79 79 # qplot() recognises the same options as plot does, and converts them to their
80   -# ggplot2 equivalents. See ?opts for more on ggplot options
  80 +# ggplot2 equivalents. See ?theme for more on ggplot options
81 81 # qplot(x, y, data = data, main="title", asp = 1)
82   -# ggplot(data, aes(x, y)) + geom_point() + opts(title = "title", aspect.ratio = 1)
  82 +# ggplot(data, aes(x, y)) + geom_point() + theme(title = "title", aspect.ratio = 1)
83 83 }
84 84
2  man/translate_qplot_lattice.Rd
@@ -67,7 +67,7 @@ qplot(mpg, wt, data = mtcars, xlab = "Miles per gallon", ylab = "Weight",
67 67 xyplot(wt ~ mpg, mtcars, aspect = 1)
68 68 qplot(mpg, wt, data = mtcars, asp = 1)
69 69
70   -# par.settings() is equivalent to + opts() and trellis.options.set()
  70 +# par.settings() is equivalent to + theme() and trellis.options.set()
71 71 # and trellis.par.get() to theme_set() and theme_get().
72 72 # More complicated lattice formulas are equivalent to rearranging the data
73 73 # before using ggplot2.
2  man/update_element.Rd
@@ -16,7 +16,7 @@
16 16 Update contents of a theme
17 17 }
18 18 \examples{
19   -x <- theme_text(size = 15)
  19 +x <- element_text(size = 15)
20 20 update_element(x, colour = "red")
21 21 # Partial matching works
22 22 update_element(x, col = "red")

0 comments on commit 6661a5b

Please sign in to comment.
Something went wrong with that request. Please try again.