2016-10-12 31 views
-2

所以有什麼想法如何做到這一點,請? 在此先感謝。區分螺旋圖中的天

這裏是我的data幾乎5周

head(All.smry) 
Source: local data frame [6 x 7] 
Groups: day [1] 

     day hour.group meanTT   spiralTime Speed DayName Monthes 
     <date>  <dbl> <dbl>    <dttm> <dbl> <fctr> <fctr> 
1 2016-09-04  13.00 7.340000 2016-09-04 13:00:00 29.82016 Sunday September 
2 2016-09-04  13.25 6.580000 2016-09-04 13:15:00 33.26444 Sunday September 
3 2016-09-04  13.50 5.731111 2016-09-04 13:30:00 38.19155 Sunday September 
4 2016-09-04  13.75 5.764444 2016-09-04 13:45:00 37.97070 Sunday September 
5 2016-09-04  14.00 5.915556 2016-09-04 14:00:00 37.00075 Sunday September 
6 2016-09-04  14.25 6.012222 2016-09-04 14:15:00 36.40584 Sunday September 

這裏」我的數據thew總結

summary(All.smry) 
     day    hour.group  meanTT   spiralTime     
Min. :2016-09-04 Min. : 0.00 Min. : 3.950 Min. :2016-09-04 13:00:00 
1st Qu.:2016-09-14 1st Qu.: 6.00 1st Qu.: 4.533 1st Qu.:2016-09-14 04:37:30 
Median :2016-09-23 Median :12.00 Median : 5.552 Median :2016-09-23 17:45:00 
Mean :2016-09-23 Mean :11.92 Mean : 5.910 Mean :2016-09-23 17:42:08 
3rd Qu.:2016-10-03 3rd Qu.:18.00 3rd Qu.: 6.738 3rd Qu.:2016-10-03 06:52:30 
Max. :2016-10-12 Max. :23.75 Max. :26.476 Max. :2016-10-12 20:00:00 

    Speed    DayName   Monthes  
Min. : 8.267 Friday :480 October :1137 
1st Qu.:32.486 Monday :566 September:2530 
Median :39.423 Saturday :480     
Mean :39.546 Sunday :524     
3rd Qu.:48.282 Thursday :480     
Max. :55.413 Tuesday :576     
        Wednesday:561  

這裏的代碼我使用

Title <- "SpiralGraph From GoogleTraffic" 
SubTitle <- paste("From",min(as.Date(All$spiralTime)),"To", max(as.Date(All$spiralTime)),sep = " ") 
RoadName <- paste("For",name,sep = " ") 


ggplot(All.smry, aes(x=as.numeric(hour.group), xend=as.numeric(hour.group) + 0.25, 
          y=spiralTime, yend=spiralTime, colour=meanTT)) + 
    geom_segment(size=1.1) + 
    scale_x_continuous(limits=c(0,24), breaks=0:23, minor_breaks=0:24, 
        labels=paste0(rep(c(12,1:11),2), rep(c("AM","PM"),each=12))) + 
    scale_y_datetime(limits=range(All.smry$spiralTime) + c(-3*24*3600,0), 
        breaks=seq(min(All.smry$spiralTime), max(All.smry$spiralTime),"1 day"), 
        date_labels="%b %e") + 
    scale_colour_gradientn(colours=c("#009966","orange","#FF0000","#660000")) + 
    coord_polar() + 
    theme_bw(base_size=10) + 
    labs(x="Hour",y="Day",color="Mean Travel Time") + 
    theme(panel.grid.minor.x=element_line(colour="grey60", size=0.3))+ 
    theme(axis.title.y=element_blank(),axis.text.y=element_blank(),axis.ticks.y=element_blank() 
     ,axis.title.x=element_blank())+ 
    ggtitle(bquote(atop(bold(.(Title)), atop(italic(.(SubTitle)),italic(.(RoadName)))))) + 
    theme(axis.title.y=element_blank(),axis.text.y=element_blank(),axis.ticks.y=element_blank() 
     ,axis.title.x=element_blank())+theme(text = element_text(size=7)) 

這裏是一個事先知情同意我的圖

enter image description here

因此,任何幫助嗎?..我想有線路覆蓋日子裏,我想告訴他們,並顯示到傳說吧

+1

我試圖下載數據,但它需要我登錄到Dropbox - 您確定您已將其設置爲公共鏈接嗎? – jakub

+0

@ jakub,sry,我編輯它。 –

+1

使用[geom_hline](http://docs.ggplot2.org/current/geom_abline.html)。例如:'geom_hline(yintercept = as.numeric(as.POSIXct(「2016-09-15」)))' – Blacksad

回答

1

嘗試刪除coord_polar()有更好的理解發生了什麼。

您可以在現有的彩色對角線條之間添加對角線,有點像我在我的評論中所說的。這需要一些調整,但它應該工作。

另一種解決方案是直接的顏色欄上採取行動,使用linetype(見http://sape.inf.usi.ch/quick-reference/ggplot2/linetype到已知的線型可用)

All.smry$weekDayNumber <- strftime(All.smry$spiralTime, "%u") 
All.smry[which(All.smry$weekDayNumber <=5), "momentOfWeek"] <- "weekDay" 
All.smry[which(All.smry$weekDayNumber > 5), "momentOfWeek"] <- "weekEnd" 

ggplot(All.smry, aes(x=as.numeric(hour.group), 
        xend=as.numeric(hour.group) + 0.25, 
        y=spiralTime, 
        yend=spiralTime, 
        colour=meanTT)) + 
    geom_segment(aes(linetype = momentOfWeek), size=1.1) + 
    scale_linetype_manual(name = "Moment of week", values = c("solid","dashed"), labels = c("Week day", "Week-end"), breaks = c("weekDay", "weekEnd")) + 
... 
+0

我編輯了我的問題,可否請檢查它的結束? –

+1

哼,這是因爲兩個破折號之間的空間在小圓圈中比在大圓圈中小。用'dotted'代替'dashed'來看看我的意思。看起來'linetype'不是爲'coord_polar'設計的!我明天會看看。 – Blacksad

+0

我再次編輯我的問題,我會等待你,我會與我自己解決它,直到你來,非常感謝。 –

1

你真的需要一個螺旋? 因爲如果沒有,你可以做這樣的事情:

library("scales")  
ggplot(All.smry, aes(x = as.Date(day), y = hour.group)) + 
    geom_raster(aes(fill = meanTT), na.rm = TRUE) + 
    scale_fill_gradientn(colours=c("#009966","orange","#FF0000","#660000")) + 
    scale_x_date(breaks = date_breaks("weeks")) + 
    scale_y_continuous(name = "Time", limits = c(0,24), breaks = 0:24, expand = c(0,0.2)) 

,這將給你說:

enter image description here

它需要一些調整,但它可能做的工作。

+0

我必須使用螺旋圖,但這張圖看起來不錯,我找到了一個解決方案,但我又遇到了另一個問題,我會改變我的帖子,並把我的代碼與圖片,我無法顯示的傳說,所以我沒有寫下我的答案,如果你知道如何展示傳奇plz寫我的答案作爲你的向我展示如何顯示傳說。 –