hrbrmstr / metricsgraphics

:chart_with_upwards_trend: htmlwidget interface to the MetricsGraphics.js D3 chart library
http://hrbrmstr.github.io/metricsgraphics/
Other
132 stars 35 forks source link

mjs_add_line does not display X values correctly with mjs_axis_x(format="plain") #50

Open zhitkovk opened 7 years ago

zhitkovk commented 7 years ago

Hi,

When moving the cursor over the line I get the wrong data displayed in the top right corner. For now it seems to me that the problem is only encountered with format="plain".

Example code:

h <- data.frame(a = c(4:8), b = seq(2000, 6000, 1000), d = rep(4000, 5))

h %>%
  mjs_plot(x = a,
           y = b) %>%
  mjs_add_line(d) %>%
  mjs_axis_x(xax_format = "plain")

The problem can be tracked on printscreen: both lines are named 'a' and contain undefined as x-values.

default

With X variable of class Date there seems to be no problem.

str() of the same data, but now a contains dates

'data.frame':   5 obs. of  3 variables:
 $ a: Date, format: "2010-05-31" "2011-06-30" "2012-11-30" "2013-01-31" ...
 $ b: num  2000 3000 4000 5000 6000
 $ d: num  4000 4000 4000 4000 4000

Works fine:

default