-
Notifications
You must be signed in to change notification settings - Fork 171
Options for more streamlined DSL for props() #48
Comments
Another option from JJ. Like Option 4 + 5:
That way the standard operations (scaled expressions and unscaled constants) just work |
Option 1.6
I personally really like |
@jcheng5 unfortunately that's really hard to make work because of the |
Oh, so is Option 1.5 equally hard to make work? That's what I was basing it off of. |
Oh n/m I get it now. |
Is option 3 workable? |
@jcheng5 option 3 has the same problem - I can make it work with some heuristics, but it fail 1% of the time with weird error messages. Option 1.5 is easier to make work because it uses quote as well as ~. |
These are some of the possibilities for the DSL for specifying within the
props()
function. This function has the approximately the same purpose as theaes()
function in ggplot2.A property is either scaled or unscaled. Examples of scaled values are: numeric value mapped to x position, and a categorical variable mapped to colors. Examples of unscaled values are: specifying a constant color for points, like "red", or a column in a data set that contains raw color names, like "#000000", "#ffffff", "red", etc.
The value should also be an expression to be evaluated at render time, a constant value, or a (reactive) input object.
Here are there are six different combinations and some examples of their use:
aes(x = wt)
in ggplot2.c("red", "red", "black")
."red"
.1 and 5 will probably be the most common use cases.
The options shown below are a subset of a long list of alternatives.
Option 1.5
x ~ quote(mpg)
x ~ 1
x ~ input_slider()
fill = quote(col)
fill = "red"
fill = input_slider()
y = prop(...)
Cons: most common operation is longest (~ + quote).
Option 3
x ~ mpg
x ~ 1
x ~ input_slider()
fill ~ I(col)
fill ~ I("red")
fill ~ I(input_slider())
y = prop(...)
Cons:
Option 4
x ~ mpg
x ~ 1
y = input_slider()
fill ~ I(col)
fill = "red"
, orfill = I("red")
fill = I(input_slider())
y = prop(...)
Pros: No non-standard evaluation, Hadley can implement easily
Cons: lack of symmetry, confusing
Option 5
By default, expressions are evaluated
~
means to not evaluate the expression=
means to use scale = TRUE:=
means to use scale = FALSEx = ~mpg
x = 1
x = input_slider()
fill := ~col
fill := "red"
fill := input_slider()
y = prop(...)
Option 9
~
means to not evaluate the expression. Also default to scale=TRUE.=
means to evaluate the expression. Also default to scale=FALSE.scaled() means to force the object to have scale=TRUE
unscaled() means to force the object to have scaled=FALSE
x ~ mpg
x = scaled(1)
x = scaled(input_slider())
fill ~ unscaled(col)
fill = "red"
fill = input_slider()
y = prop(...)
Option 10
By default, expressions are evaluated
~
means to not evaluate the expressionDefault is to use scale=TRUE
I()
means to use scale=FALSEx = ~mpg
x = 1
x = input_slider()
fill = ~I(col)
fill = I("red")
fill = I(input_slider())
y = prop(...)
The text was updated successfully, but these errors were encountered: