2015-02-09 49 views
2

我這樣的數據:R:ggvis - 在間隔繪X標籤

structure(list(date = structure(1:31, .Label = c("2014-12-01", 
"2014-12-02", "2014-12-03", "2014-12-04", "2014-12-05", "2014-12-06", 
"2014-12-07", "2014-12-08", "2014-12-09", "2014-12-10", "2014-12-11", 
"2014-12-12", "2014-12-13", "2014-12-14", "2014-12-15", "2014-12-16", 
"2014-12-17", "2014-12-18", "2014-12-19", "2014-12-20", "2014-12-21", 
"2014-12-22", "2014-12-23", "2014-12-24", "2014-12-25", "2014-12-26", 
"2014-12-27", "2014-12-28", "2014-12-29", "2014-12-30", "2014-12-31" 
), class = "factor"), sessions = c(1932L, 1828L, 2349L, 8192L, 
3188L, 3277L, 2846L, 2541L, 5434L, 4290L, 2059L, 2080L, 2111L, 
3776L, 1989L, 1844L, 3641L, 1283L, 1362L, 1568L, 2882L, 1212L, 
957L, 851L, 928L, 1435L, 1115L, 1471L, 1128L, 1022L, 768L), id = 1:31), .Names = c("date", 
"sessions", "id"), row.names = c(NA, -31L), drop = TRUE, class = c("tbl_df", 
"tbl", "data.frame")) 

我要繪製的X標籤,但並不適用於所有日期,但第一個,中間,和樂特日期。像谷歌分析:

enter image description here

1.這是我ploting(與標籤X的所有日期)正常碼:

EvolucionVisitas %>% ggvis(x= ~date, y= ~sessions, key := ~id) %>% 
    layer_points() %>% 
    add_tooltip(mysessions ,"hover") %>% 
    layer_paths() 

enter image description here

2。這是我的代碼,用於修復x標籤,但是現在不打印:

EvolucionVisitas %>% ggvis(x= ~date, y= ~sessions, key := ~id) %>% 
    layer_points() %>% 
    add_tooltip(mysessions ,"hover") %>% 
    layer_paths() %>% 
    add_axis("x", 
      value=c(EvolucionVisitas$date[1], EvolucionVisitas$date[round(length(EvolucionVisitas$date)/2,0)], 
        tail(EvolucionVisitas$date, n=1)), 
      properties=axis_props(
      labels=list(angle=90, fontSize = 10))) 

回答

1

試試這個:

EvolucionVisitas %>% ggvis(x= ~date, y= ~sessions, key := ~id) %>% 
    layer_points() %>% 
    add_tooltip(mysessions ,"hover") %>% 
    layer_paths() %>% 
    add_axis("x", value=c(as.character(EvolucionVisitas$date[1]),as.character(EvolucionVisitas$date[round(length(EvolucionVisitas$date)/2,0)]), 
         as.character(tail(EvolucionVisitas$date, n=1)))) 

值轉換爲字符開了竅。

+0

完美的作品。謝謝不錯 – 2015-02-10 02:09:13