Created
May 23, 2014 20:22
-
-
Save corynissen/1d1bd39e906f6ebdef34 to your computer and use it in GitHub Desktop.
trying dual axis scatterplots with dates...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cs <-c("13-10-30 12:30:00", "13-10-30 12:35:00", "13-10-30 12:40:00", | |
"13-10-30 12:45:00", "13-10-30 12:50:00", "13-10-30 12:55:00") | |
x <-strptime(cs, "%y-%m-%d %H:%M:%S") | |
dfr <-data.frame(date=as.POSIXct(x,origin="1970-01-01"), | |
value1=c(1.5,1.25,.75,2.1,1.3,1.4), | |
value2=c(3.5,3.25,1.75,.1,6.3,2.4)) | |
h1 <- Highcharts$new() | |
h1$chart(type = "scatter") | |
h1$chart(zoomType = "xy") | |
h1$xAxis(type = "datetime", data=as.POSIXct(dfr$date,origin="1970-01-01")) | |
h1$series(name = 'Temperature', type = 'scatter', color = '#000099', | |
data = dfr$value1) | |
h1$series(name = 'Humidity', type = 'scatter', color = '#FF0000', | |
data = dfr$value2, yAxis=1) | |
h1$yAxis(list(list(title = list(text = 'Temperature'), opposite = FALSE), | |
list(title = list(text = 'humidity_rh'), opposite = TRUE))) |
Here is, at least for the first issue.
the second one is easy.
cs <-c("13-10-30 12:30:00", "13-10-30 12:35:00", "13-10-30 12:40:00",
"13-10-30 12:45:00", "13-10-30 12:50:00", "13-10-30 12:55:00")
x <-strptime(cs, "%y-%m-%d %H:%M:%S")
dfr <-data.frame(date=1000*as.numeric(as.POSIXct(x,origin="1970-01-01", tz="UTC")),
value1=c(1.5,1.25,.75,2.1,1.3,1.4),
value2=c(3.5,3.25,1.75,.1,6.3,2.4))
h1 <- Highcharts$new()
h1$chart(type = "scatter")
h1$chart(zoomType = "xy")
h1$xAxis(type = "datetime")
h1$series(name = 'Temperature', type = 'scatter', color = '#000099',
data = toJSONArray2(dfr[c(1, 2)], json = F, name = F))
h1$series(name = 'Humidity', type = 'scatter', color = '#FF0000',
data = toJSONArray2(dfr[c(1, 3)], json = F, name = F), yAxis=1)
h1$yAxis(list(list(title = list(text = 'Temperature'), opposite = FALSE),
list(title = list(text = 'humidity_rh'), opposite = TRUE)))
h1
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How would you want the dates to show up in your x-Axis. I think the issue is two fold. One is making Highcharts understand the date correctly, and two is to format the label as desired.