If We Assign Variable Names
If We Assign Variable Names
Since these arguments map data values to a visual range by default, you will
obtain unexpected results if you try to specify the visual range directly, as in the
top portion of Figure 2.3. If you want to specify the visual range directly, use
the I() function to declare this value to be taken ‘AsIs’, as in the bottom portion of
Figure 2.3. Throughout this book, you’ll see lots of examples that leverage these
arguments, especially in Chapter 3. Another good resource to learn more about
these arguments (especially their defaults) is the R documentation page available
by entering help(plot_ly) in your R console.
# doesn't produce black bars
plot_ly(diamonds, x = ~cut, color = "black")
# produces red bars with black outline
plot_ly(
diamonds,
x = ~cut,
color = I("red"),
stroke = I("black"),
span = I(2)
)