The following:
library(ggvis)
gg <- ggvis(df, props(~x, ~y, stroke = ~factor(id)))
gg <- gg + layer_line(props(strokeWidth := ~id*4))
gg
produces:
I had to tweak the multiplier for the strokeWidth
to get it to be a bit thicker, but that should be a good starting point for you. Remember ggivs
is based on Vega so getting familiar with the terminology in that new graphics grammar is going to almost be a requirement to understand how to "think" in ggvis
.
Here's an example of doing this more properly (and more ggplot2
-like with scale_quantitative
:
gg <- ggvis(df, props(~x, ~y, stroke = ~factor(id)))
gg <- gg + layer_line(props(strokeWidth = ~id))
gg <- gg + scale_quantitative("strokeWidth",
trans="linear",
domain=range(df$id),
range=c(1,10))
gg
Doing a ?scale_quantitative
or reviewing the "scales" online examples should give you a good idea of your options for getting the desired effect.
I also should point out the use of "=
" vs ":=
" in the second example. From the ggvis
site:
The props() function uses the = operate for mapping (scaled), and the := operator for setting (unscaled). It also uses the ~ operator to indicate that an expression should be evaluated in the data (and in ggvis, the data can change); without the ~ operator, the expression is evaluated immediately in the current environment.