Alsqer Alsqer - 1 month ago 10
R Question

Distinguish between days in Spiral graph

so is there any idea for how to do this ,Please ?
Thanks in advance.

here's my data for almost 5weeks

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


here' thew summary of my data

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


here's the code i use

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))


here's a pic for my graph

enter image description here

So, any help please ?.. i wanna have the lines covers the days i wanna show and show them into the legends bar

Answer

I made a trick but it works fine, i can't add colours to the ablines and show these colours in the legends bar .

  geom_abline(intercept = as.numeric(as.POSIXlt.date(Weekends)+8.5*3600),slope =3200 ,size=0.4,linetype="dashed", show.legend=TRUE)+
  geom_abline(intercept = as.numeric(as.POSIXlt.date(Eid)+8.5*3600),slope =3200 ,size=0.4,show.legend=TRUE)+

  geom_abline(aes(intercept = as.numeric(as.POSIXct(Weekends[1])+8.5*3600),linetype = "Weekends",slope=3200),show.legend = TRUE,size=0.0001)+
  geom_abline(aes(intercept = as.numeric(as.POSIXct(Eid[1])+8.5*3600),linetype = "Eid",slope=3200),show.legend = TRUE,size=0.0001)+

  scale_linetype_manual(name="Days",values = c("solid","dashed"))+  
Comments