Skip to content

Instantly share code, notes, and snippets.

@schochastics
Created November 12, 2019 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schochastics/7d39e47effc2eeacd6c8139ba4d5af9f to your computer and use it in GitHub Desktop.
Save schochastics/7d39e47effc2eeacd6c8139ba4d5af9f to your computer and use it in GitHub Desktop.
time prediction
library(tidyverse)
library(ggforce)
d <- tibble(x = c(1, 6, 10, 23,18), xpred = c(4, 8, 11, 2,22), y = 1:5, id = factor(1:5))
n <- nrow(d)+1
time_angle <- tibble(hour=1:24,angle=0.25*60*hour)
d$start <- time_angle$angle[d$x]*pi/180
d$end <- time_angle$angle[d$xpred]*pi/180
d$r <- d$y
d$start <- ifelse(d$start>d$end,2*pi-d$start,d$start)
clock <- tibble(x0=0,y0=0,r=n)
ggplot(d) +
geom_arc(aes(x0 = 0, y0 = 0, r = r, start = start, end = end),
arrow = arrow(angle = 20, length = unit(0.15, "inches"),
ends = "last", type = "closed"))+
geom_circle(data=clock,aes(x0=x0,y0=y0,r=r))+
geom_segment(x=0,xend=0,y=-n,yend=n,col="grey66")+
geom_segment(x=-n,xend=n,y=0,yend=0,col="grey66")+
annotate("text",x=n,y=0,label="6",size=10,hjust=0)+
annotate("text",x=-n,y=0,label="18",size=10,hjust=1)+
annotate("text",x=0,y=n,label="24",size=10,vjust=0)+
annotate("text",x=0,y=-n,label="12",size=10,vjust=1)+
coord_fixed(clip = "off")+
theme_void()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment