gvisMotionChart - 日期格式不会显示 - “date.format =”%m“

时间:2015-03-01 04:09:00

标签: r googlevis

我是2014-01-01至2015-02-26的数据。 我想在googleVis包中的MotionChart中显示它,时间显示:月份,而不是具体日期:" 1/1/15"。

我这样称呼数据:

Ikasa_Adwords <- read.csv("...Ikasa_Adwords.csv", 
                          header = T)


Ikasa_Adwords$date <- as.Date(Ikasa_Adwords$date)

然后应用它来生成MotionChart:

M <- gvisMotionChart(Ikasa_Adwords, idvar="campaign", timevar="date",
                      xvar="ad.cost",yvar="impressions", date.format="%m")

plot(M)

图像:

enter image description here

如你所见:我已经&#34; date.format =&#34;%m&#34;但是,仍然是日期,因为&#34; 1/1/15&#34;。为什么呢?

我的数据(第一行):

      date             campaign         sessions    ad.cost ad.clicks   impressions
1   2014-01-01  Brand Search - Motos      0           1.35      7        21
2   2014-01-01  Brand Search - Autos      2           0.28      1        6
3   2014-01-01  Brand Search - Aviones    21          3.76      20       187
4   2014-01-01  Brand Search - Barcos     7           1.21      3        10
5   2014-01-01  Brand Search - Camiones   9           1.37      6        33

来自str()函数的OutPut:

 str(Ikasa_Adwords)
'data.frame':   7878 obs. of  6 variables:
 $ date       : Date, format: "2014-01-01" "2014-01-01" "2014-01-01" ...
 $ campaign   : Factor w/ 45 levels "(not set)","Brand Search - Motos,..: 2 3 5 7 9 10 12 14 16 17 ...
 $ sessions   : int  0 2 21 7 9 14 0 9 11 5 ...
 $ ad.cost    : num  1.35 0.28 3.76 1.21 1.37 ...
 $ ad.clicks  : int  7 1 20 3 6 9 1 9 7 4 ...
 $ impressions: int  21 6 187 10 33 84 9 105 47 25 ...

1 个答案:

答案 0 :(得分:0)

这个例子实际上好一点,它可以帮到你。

myStateSettings <-'
{"xZoomedDataMin":1199145600000,"colorOption":"2",
"duration":{"timeUnit":"M","multiplier":1},"yLambda":1,
"yAxisOption":"4","sizeOption":"_UNISIZE",
"iconKeySettings":[],"xLambda":1,"nonSelectedAlpha":0,
"xZoomedDataMax":1262304000000,"iconType":"LINE",
"dimensions":{"iconDimensions":["dim0"]},
"showTrails":false,"uniColorForNonSelected":false,
"xAxisOption":"_TIME","orderedByX":false,"playDuration":15000,
"xZoomedIn":false,"time":"2010","yZoomedDataMin":0,
"yZoomedIn":false,"orderedByY":false,"yZoomedDataMax":100}
'
M6a <- gvisMotionChart(Fruits, "Fruit", "Year",
                       options=list(state=myStateSettings))
plot(M6a)

"timeUnit":"M"更改为"timeUnit":"Y"时,请注意区别;这可能会有所帮助。