I've been trying to get an x-axis to support a time using gvisLineChart
. Trouble is, it's always interpreted as a character.
library(googleVis)
dat <- data.frame(time=as.POSIXct(c("2012-09-23 12:00:00", "2012-04-25 18:00:00", "2011-03-01 02:34:00")),
x=rnorm(3), y=rnorm(3))
plot(gvisLineChart(dat))
How can I get the x axis to be properly interpreted as a date? I'm fairly certain options=list(hAxis.format:"...")
is the solution somehow, but various formats including "yyyy-MM-dd HH:mm:ss", but they don't seem to fix my problem at all.
In summary, I want a continuous datetime axis as suggested in possible in the Google Chart Tools docs.
I contacted the author of the package, Markus Gesmann, and he managed to solve the problem. The issue was that the CRAN version of googleVis (0.3.3) was not accepting date or datetime columns (in R, the POSIX and Date classes).
The following code does not produce the expected result under 0.3.3:
library(googleVis)
x <- as.Date(c(Sys.Date()+sample(1:100, 3)))
df <- data.frame(country=c("US", "GB", "BR"),
val1=c(1,3,4),
val2=c(23,12,32),
year=2011:2013,
num=c(1.2, 2.3, 3.4),
date=x)
Line4 <- gvisLineChart(df, xvar="date", yvar=c("val1", "val2"))
plot(Line4)
But it does produce a continuous time axis under 0.4.1 which is the current development version.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With