1414# ' @export
1515# ' @examples
1616# ' # Chart-level axis titles (no marks yet)
17- # ' g2(mtcars, x = ' mpg', y = 'hp' ) |>
17+ # ' g2(mtcars, hp ~ mpg) |>
1818# ' axis_('x', title = 'Miles per Gallon') |>
1919# ' axis_('y', title = 'Horsepower')
2020# '
2121# ' # Mark-level axis for dual-axis chart
2222# ' df = data.frame(x = 1:5, a = c(1, 4, 2, 5, 3), b = c(100, 200, 150, 300, 250))
23- # ' g2(df, x = 'x' ) |>
23+ # ' g2(df, ~ x ) |>
2424# ' mark_interval(encode = list(y = 'a')) |>
2525# ' mark_line(encode = list(y = 'b')) |>
2626# ' scale_y(independent = TRUE) |>
@@ -44,7 +44,7 @@ axis_ = function(chart = NULL, channel, ...) {
4444# ' @inheritParams axis_
4545# ' @export
4646# ' @examples
47- # ' g2(mtcars, x = ' mpg', y = 'hp' ) |>
47+ # ' g2(mtcars, hp ~ mpg) |>
4848# ' axis_x(title = 'Miles per Gallon')
4949axis_x = function (chart = NULL , ... ) axis_(chart , ' x' , ... )
5050
@@ -53,7 +53,7 @@ axis_x = function(chart = NULL, ...) axis_(chart, 'x', ...)
5353# ' @inheritParams axis_
5454# ' @export
5555# ' @examples
56- # ' g2(mtcars, x = ' mpg', y = 'hp' ) |>
56+ # ' g2(mtcars, hp ~ mpg) |>
5757# ' axis_y(title = 'Horsepower')
5858axis_y = function (chart = NULL , ... ) axis_(chart , ' y' , ... )
5959
@@ -69,7 +69,7 @@ axis_y = function(chart = NULL, ...) axis_(chart, 'y', ...)
6969# ' @return The modified `g2` object.
7070# ' @export
7171# ' @examples
72- # ' g2(iris, x = ' Sepal.Width', y = ' Sepal.Length' , color = ' Species' ) |>
72+ # ' g2(iris, Sepal.Length ~ Sepal.Width , color = ~ Species) |>
7373# ' legend_('color', position = 'right')
7474legend_ = function (chart = NULL , channel , ... ) {
7575 mod = check_chart(legend_ , chart , c(if (! missing(channel )) list (channel ), list (... )))
@@ -96,7 +96,7 @@ legend_ = function(chart = NULL, channel, ...) {
9696# ' @inheritParams legend_
9797# ' @export
9898# ' @examples
99- # ' g2(iris, x = ' Sepal.Width', y = ' Sepal.Length' , color = ' Species' ) |>
99+ # ' g2(iris, Sepal.Length ~ Sepal.Width , color = ~ Species) |>
100100# ' legend_color(position = 'right')
101101legend_color = function (chart = NULL , ... ) legend_(chart , ' color' , ... )
102102
@@ -105,7 +105,7 @@ legend_color = function(chart = NULL, ...) legend_(chart, 'color', ...)
105105# ' @inheritParams legend_
106106# ' @export
107107# ' @examples
108- # ' g2(mtcars, x = ' mpg', y = 'hp', size = 'wt' ) |>
108+ # ' g2(mtcars, hp ~ mpg, size = ~ wt ) |>
109109# ' legend_size(position = 'bottom')
110110legend_size = function (chart = NULL , ... ) legend_(chart , ' size' , ... )
111111
@@ -114,7 +114,7 @@ legend_size = function(chart = NULL, ...) legend_(chart, 'size', ...)
114114# ' @inheritParams legend_
115115# ' @export
116116# ' @examples
117- # ' g2(iris, x = ' Sepal.Width', y = ' Sepal.Length' , shape = ' Species' ) |>
117+ # ' g2(iris, Sepal.Length ~ Sepal.Width , shape = ~ Species) |>
118118# ' legend_shape(position = 'bottom')
119119legend_shape = function (chart = NULL , ... ) legend_(chart , ' shape' , ... )
120120
@@ -123,7 +123,7 @@ legend_shape = function(chart = NULL, ...) legend_(chart, 'shape', ...)
123123# ' @inheritParams legend_
124124# ' @export
125125# ' @examples
126- # ' g2(mtcars, x = ' mpg', y = 'hp', opacity = 'wt' ) |>
126+ # ' g2(mtcars, hp ~ mpg, opacity = ~ wt ) |>
127127# ' legend_opacity(position = 'bottom')
128128legend_opacity = function (chart = NULL , ... ) legend_(chart , ' opacity' , ... )
129129
@@ -135,7 +135,7 @@ legend_opacity = function(chart = NULL, ...) legend_(chart, 'opacity', ...)
135135# ' @return The modified `g2` object.
136136# ' @export
137137# ' @examples
138- # ' g2(mtcars, x = ' mpg', y = 'hp' ) |>
138+ # ' g2(mtcars, hp ~ mpg) |>
139139# ' title_('Motor Trend Cars', subtitle = 'mpg vs hp')
140140title_ = function (chart = NULL , text , ... ) {
141141 mod = check_chart(title_ , chart , c(if (! missing(text )) list (text ), list (... )))
@@ -160,7 +160,7 @@ title_ = function(chart = NULL, text, ...) {
160160# ' @return The modified `g2` object.
161161# ' @export
162162# ' @examples
163- # ' g2(mtcars, x = ' mpg', y = 'hp' ) |>
163+ # ' g2(mtcars, hp ~ mpg) |>
164164# ' tooltip_(crosshairs = TRUE)
165165tooltip_ = function (chart = NULL , ... ) {
166166 mod = check_chart(tooltip_ , chart , list (... ))
@@ -180,21 +180,21 @@ tooltip_ = function(chart = NULL, ...) {
180180# ' multiple times to add several label layers.
181181# '
182182# ' @param chart A `g2` object.
183- # ' @param ... Label options such as `text` (channel name), `position`,
184- # ' `formatter`, `style`.
183+ # ' @param ... Label options such as `text` (channel name as `~col` or
184+ # ' `'col'`), `position`, ` formatter`, `style`.
185185# ' @return The modified `g2` object.
186186# ' @export
187187# ' @examples
188188# ' df = data.frame(x = c('A', 'B', 'C'), y = c(3, 7, 2))
189- # ' g2(df, x = 'x', y = 'y' ) |>
190- # ' labels_(text = 'y' , position = 'inside')
189+ # ' g2(df, y ~ x ) |>
190+ # ' labels_(text = ~ y , position = 'inside')
191191labels_ = function (chart = NULL , ... ) {
192192 mod = check_chart(labels_ , chart , list (... ))
193193 if (! is.null(mod )) return (mod )
194194 was_empty = ! length(chart $ layers )
195195 if (was_empty ) chart = ensure_mark(chart )
196196 n = if (was_empty ) 1L else length(chart $ layers )
197- chart $ layers [[n ]]$ labels = c(chart $ layers [[n ]]$ labels , list (list (... )))
197+ chart $ layers [[n ]]$ labels = c(chart $ layers [[n ]]$ labels , list (as_vars( list (... ) )))
198198 chart
199199}
200200
@@ -206,7 +206,7 @@ labels_ = function(chart = NULL, ...) {
206206# ' @return The modified `g2` object.
207207# ' @export
208208# ' @examples
209- # ' g2(mtcars, x = ' mpg', y = 'hp' ) |>
209+ # ' g2(mtcars, hp ~ mpg) |>
210210# ' style_mark(fill = 'steelblue', stroke = 'white', lineWidth = 1)
211211style_mark = function (chart = NULL , ... ) {
212212 mod = check_chart(style_mark , chart , list (... ))
@@ -228,7 +228,7 @@ style_mark = function(chart = NULL, ...) {
228228# ' @return The modified `g2` object.
229229# ' @export
230230# ' @examples
231- # ' g2(mtcars, x = ' mpg', y = 'hp' ) |>
231+ # ' g2(mtcars, hp ~ mpg) |>
232232# ' slider_('x')
233233slider_ = function (chart = NULL , channel , ... ) {
234234 mod = check_chart(slider_ , chart , c(if (! missing(channel )) list (channel ), list (... )))
@@ -244,7 +244,7 @@ slider_ = function(chart = NULL, channel, ...) {
244244# ' @inheritParams slider_
245245# ' @export
246246# ' @examples
247- # ' g2(mtcars, x = ' mpg', y = 'hp' ) |>
247+ # ' g2(mtcars, hp ~ mpg) |>
248248# ' slider_x()
249249slider_x = function (chart = NULL , ... ) slider_(chart , ' x' , ... )
250250
@@ -253,7 +253,7 @@ slider_x = function(chart = NULL, ...) slider_(chart, 'x', ...)
253253# ' @inheritParams slider_
254254# ' @export
255255# ' @examples
256- # ' g2(mtcars, x = ' mpg', y = 'hp' ) |>
256+ # ' g2(mtcars, hp ~ mpg) |>
257257# ' slider_y()
258258slider_y = function (chart = NULL , ... ) slider_(chart , ' y' , ... )
259259
@@ -266,7 +266,7 @@ slider_y = function(chart = NULL, ...) slider_(chart, 'y', ...)
266266# ' @export
267267# ' @examples
268268# ' df = data.frame(x = 1:100, y = cumsum(rnorm(100)))
269- # ' g2(df, x = 'x', y = 'y' ) |>
269+ # ' g2(df, y ~ x ) |>
270270# ' mark_line() |>
271271# ' scrollbar_('x')
272272scrollbar_ = function (chart = NULL , channel , ... ) {
@@ -284,7 +284,7 @@ scrollbar_ = function(chart = NULL, channel, ...) {
284284# ' @export
285285# ' @examples
286286# ' df = data.frame(x = 1:100, y = cumsum(rnorm(100)))
287- # ' g2(df, x = 'x', y = 'y' ) |>
287+ # ' g2(df, y ~ x ) |>
288288# ' mark_line() |>
289289# ' scrollbar_x()
290290scrollbar_x = function (chart = NULL , ... ) scrollbar_(chart , ' x' , ... )
@@ -295,7 +295,7 @@ scrollbar_x = function(chart = NULL, ...) scrollbar_(chart, 'x', ...)
295295# ' @export
296296# ' @examples
297297# ' df = data.frame(x = 1:100, y = cumsum(rnorm(100)))
298- # ' g2(df, x = 'x', y = 'y' ) |>
298+ # ' g2(df, y ~ x ) |>
299299# ' mark_line() |>
300300# ' scrollbar_y()
301301scrollbar_y = function (chart = NULL , ... ) scrollbar_(chart , ' y' , ... )
0 commit comments