I am using the great dygraphs package for R (https://rstudio.github.io/dygraphs/)
My code as of right now is:
james<-mtcars[c("mpg","drat")]
james$date<-seq(from=as.Date("2013-05-16"),to=as.Date("2013-06-16"),by="days")
x <- xts::xts(james$mpg, order.by = james$date)
p <- dygraphs::dygraph(x, main = "mpg over time", xlab = "Date", ylab = "mpg") %>%
dygraphs::dyRangeSelector() %>%
dyOptions(drawPoints = TRUE, pointSize = 2)
p
I want to scale the size of points in p by james$drat
, rather than having it fixed at 2.
How can I do this?
I know this is an old question, but I have found a potential solution using drawPointCallback
. I hope it helps someone out there. You could choose a scale either in R or JavaScript if you did not want to use the raw number.
library(dygraphs)
james<-mtcars[c("mpg","drat")]
james$date<-seq(from=as.Date("2013-05-16"),to=as.Date("2013-06-16"),by="days")
x <- xts::xts(james$mpg, order.by = james$date)
p <- dygraphs::dygraph(x, main = "mpg over time", xlab = "Date", ylab = "mpg") %>%
dygraphs::dyRangeSelector() %>%
dyOptions(drawPoints = TRUE)
p %>%
dyCallbacks("drawPointCallback" = sprintf(
"
function(g, name, ctx, canvasx, canvasy, color, radius, index) {
var drat = %s;
radius = drat[index];
return Dygraph.Circles.DEFAULT(g, name, ctx, canvasx, canvasy, color, radius)
}
",
jsonlite::toJSON(mtcars$drat)
)
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With