r - ggvis: add size property to a line -


just getting started ggvis. not particularly interesting or general question i'm afraid, not obvious me how add size property line. in particular, how replicate following plot using ggvis?

library(ggplot2)  df <- data.frame(   id = c(1,1,1,2,2,2,2),   x  = c(1,2,3,1,2,3,4),   y  = c(2,3,4,1,1,2,3) )  ggplot(df, aes(x, y, colour = as.factor(id), size = id)) +   geom_line() 

also, high enough reputation create ggvis tag? cheers.

the following:

library(ggvis)  gg <- ggvis(df, props(~x, ~y, stroke = ~factor(id))) gg <- gg + layer_line(props(strokewidth := ~id*4)) gg 

produces:

plot

i had tweak multiplier strokewidth bit thicker, should starting point you. remember ggivs based on vega getting familiar terminology in new graphics grammar going requirement understand how "think" in ggvis.

here's example of doing more (and more ggplot2-like 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 

sq

doing ?scale_quantitative or reviewing "scales" online examples should give idea of options getting desired effect.

i should point out use of "=" vs ":=" in second example. ggvis site:

the props() function uses = operate mapping (scaled), , := operator setting (unscaled). uses ~ operator indicate expression should evaluated in data (and in ggvis, data can change); without ~ operator, expression evaluated in current environment.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -