如何在 R 中使用 dygraph 绘制散点图,包括鼠标悬停日期? [英] How do I do a scatter plot with dygraph in R, including mouseover date?

查看:51
本文介绍了如何在 R 中使用 dygraph 绘制散点图,包括鼠标悬停日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 3 组数据,都在同一时间序列中,但是我想将数据集 1 绘制为 x 轴,将数据集 2 和 3 绘制为 y 轴.我希望数据集 2 和 3 位于单独的图中.此外,当我将鼠标悬停在数据点上时,我还想查看数据点的日期.我想在 R 中使用 dygraph/tauchart 来做到这一点.

另一点是图形的缩放.

这是我的 xts 格式数据点的示例.

 系列 1 系列 2 系列 32006 年 1 月 28397 7.55 113762006 年 2 月 21255 7.63 87022006 年 3 月 24730 7.62 100112006 年 4 月 18981 7.50 79422006 年 5 月 25382 7.47 104902006 年 6 月 23874 7.53 10156

解决方案

不确定是否使用 xts 对象和 dygraph 执行此操作,但如果您的数据位于数据框中,则使用新的 taucharts 包.

将部分数据创建为数据框:

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

安装和加​​载 taucharts:

devtools::install_github("hrbrmstr/taucharts")图书馆(taucharts")

使用 taucharts 创建带有工具提示的散点图:

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

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.

解决方案

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()

这篇关于如何在 R 中使用 dygraph 绘制散点图,包括鼠标悬停日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆