How do I do a scatter plot with dygraph in R, including mouseover date?

核能气质少年 提交于 2019-12-13 05:58:45

问题


I have 3 set of data, both in the same time series, however I want to plot data set 1 as x axis and data set 2 and 3 as y axis. I would like data set 2 and 3 to be in a separate plot. In addition, when I mouse over the data point, I would like to see the date of the data point as well. I would like to use dygraph/tauchart in R to do this.

Another point would be to zooming of the graph as well.

This is the example of my data points in xts format.

         Series 1 Series 2 Series 3
Jan 2006    28397     7.55    11376
Feb 2006    21255     7.63     8702
Mar 2006    24730     7.62    10011
Apr 2006    18981     7.50     7942
May 2006    25382     7.47    10490
Jun 2006    23874     7.53    10156

Example I have seen to plot a scatter plot but no code was shown

Edited: I have done up some scatter plot, but there still edit problem with it. The package used is Tauchart.

  1. I cannot combined series 2 and 3 as 2 plot(Top and Bottom) separately
  2. The plot is not scalable on y axis. I tried using auto_scale in tau_guide_x and y, however, the x scale works but not the y. I have also tried using min and max, however it is not working too.

Code

Scatterplot1<-tauchart(a) %>%
    tau_point("Series.1", "Series.2") %>%
    tau_tooltip() %>% 
    tau_guide_x(label="Amount", auto_scale=FALSE) %>% 
    tau_guide_y(label="Amount", auto_scale=FALSE)

This is what I have plot and the problem come in the scaling of y axis cannot be done.


回答1:


Not sure about doing this with an xts object and dygraph, but if your data is in a data frame it's easy to do with the new taucharts package .

Create part of your data as a data frame:

months <- c("Jan 2006", "Feb 2006", "Mar 2006")
Series1 <- c(28397, 21225, 24730)
Series2 <- c(7.55, 7.63, 7.62)
mydata <- data.frame(months, Series1, Series2)

Install and load taucharts:

devtools::install_github("hrbrmstr/taucharts")
library("taucharts")

Create a scatter plot with tooltip using taucharts:

tauchart(mydata) %>%
  tau_point("Series1", "Series2") %>%
  tau_tooltip()



回答2:


You can use

{"axes": {"y": {"valueRange": [1.4, 2.5]},}



来源:https://stackoverflow.com/questions/32302736/how-do-i-do-a-scatter-plot-with-dygraph-in-r-including-mouseover-date

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!