2014-09-22 2 views
0

R에서 Google 웹 로그 분석 데이터를 분석하고 rCharts 패키지를 통해 NVD3과 함께 표시합니다. 그러나 차트의 모든 데이터 요소가 하루 일찍 (6 월 21 일과 올바른 6 월 22 일)이기 때문에 날짜가 잘못된 시간대에 설정되어 있다고 생각합니다. N.B. Google 웹 로그 분석은 적어도 웹 앱에서는 EST로보고하도록 설정되어 있습니다.R 및 D3의 날짜가 잘못되었습니다.

sources <- ga$getData(...) # Using rga to pull data from Analytics 

> dput(sources) 
structure(list(date = structure(c(16243, 16243, 16243, 16243, 
16244, 16244, 16244), class = "Date"), medium = c("(none)", "cpc", 
"organic", "referral", "(none)", "cpc", "organic"), sessions = c(9, 
50, 5, 3, 3, 68, 9)), .Names = c("date", "medium", "sessions" 
), row.names = c(NA, 7L), class = "data.frame") 

lineChart <- nPlot(sessions ~ date, group = 'medium', data = sources, type = "lineWithFocusChart") 
lineChart$xAxis(tickFormat = "#!function(d) {return d3.time.format('%b %d')(new Date(d*1000*3600*24)); }!#") # Fixing date to show only month and day (ordinal) 
lineChart$show() 
+0

R 날짜는 시간대가 없습니다 (그리고 R의 datetimes로 강제 변환 될 때 GMT의 자정이 사용됩니다). D3에 사용해야하는 날짜 등급이 있습니까? –

+0

그것은 그렇게 보인다. 그러나 불행하게도 그것은 나의 머리 위에 길을 날고있다. https://github.com/mbostock/d3/wiki/Time-Formatting – mattpolicastro

답변

1

이 해킹의 비트입니다하지만 내가하는 데 필요한 원래 통화가 (난 당신이 CST/GMT 뒤에 4시간 생각하지만, 당신이 다섯에 넷을 변경해야 할 가능성이 있습니다.이었다 왼쪽 해안에있는 이후로 7로 변경하십시오.)

lineChart$xAxis(tickFormat = "#!function(d) {return d3.time.format(
         '%b %d')(new Date(d*1000*3600*24+4*60*60*1000)); }!#") 
lineChart$show() 
+0

그래, 작동하는 것 같습니다. 상관 없어요. 해킹입니다. 디스플레이 용입니다. 도움을 주셔서 감사합니다. – mattpolicastro