Rcharts nvd3 2-D zoom possible?
Asked Answered
A

1

9

Is there a zooming function in nvd3 that I can directly type in my R source code (doesn't matter if it requires javascript as long as I don't have to change nvd3 source code)? I tried the lineWithFocusChart, but that only zooms along the x-axis, whereas I would like to ideally draw a box around the zoom section and it will zoom to where I drew the box. Even if that's not possible, if nvd3 supports any kind of 2-d zoom, that would be awesome! I have provided a reproducible example of what I have so far, but I have not found a feature for the zoom I am looking for yet. Thank you!

      library(rCharts)
      temp <- data.frame(x = 1:100, y = 1:100, z = c(rep(1,50), rep(0,50)))
      g <- nPlot(y ~ x, group = "z", data = temp, type = "lineChart")
      g$templates$script <- "http://timelyportfolio.github.io/rCharts_nvd3_templates/chartWithTitle_styled.html"
      g$set(title = "Example")  
      g$chart(transitionDuration = -1,
              tooltipContent = "#! function(key, x, y) {
                                    return 'z: ' + key + '<br/>' + 'x: ' + x + '<br/>' + 'y: ' + y 
                                  }!#", 
              showLegend = FALSE, margin = list(left = 200, 
                                                right = 100, 
                                                bottom = 100,
                                                top = 100))               
      g$xAxis(axisLabel = "x")
      g$yAxis(axisLabel = "y", width = 40)
      g
Adiana answered 16/7, 2015 at 15:4 Comment(0)
M
1

You could use Highcharts with the zoomType option.

For example:

require(rCharts)

names(iris) = gsub("\\.", "", names(iris))
g<-hPlot(SepalLength ~ SepalWidth, data = iris, color = 'Species', type = 'line')
g$chart(zoomType = 'xy')
g

You can then drag and hold on the plot to zoom in an area.

Mary answered 21/7, 2015 at 14:30 Comment(1)
I did use high charts before but had to switch since it does not allow commercial usage. The second best option I found was nvd3 in rCharts, so I am hoping to find a similar zoom capability in nvd3.Adiana

© 2022 - 2024 — McMap. All rights reserved.