Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sorting days in Calendar #2

Open
harrisonhenri opened this issue Oct 19, 2019 · 3 comments
Open

Sorting days in Calendar #2

harrisonhenri opened this issue Oct 19, 2019 · 3 comments

Comments

@harrisonhenri
Copy link

Dear @royfrancis , thank you for this great calendar example!

I am a developer of a Shiny system and would like to know if there is any possibility of organizing this calendar like any calendar (eg calendar in Windows 10) with days starting left and ending right?

image

@royfrancis
Copy link
Owner

I haven't tried it, but I am guessing it's just a matter of changing X and Y axes. Or am I missing something?

@harrisonhenri
Copy link
Author

I have tried changing X and Y axes, but this was the result:

image

@royfrancis
Copy link
Owner

I got some time to look into this today. Maybe this is what you are after?

plot

dfr <- data.frame(date=seq(as.Date('2019-06-11'),as.Date('2019-08-12'),by=1))
dfr$day <- factor(strftime(dfr$date,format="%a"),levels=format(seq(as.Date('2019-10-21'),as.Date('2019-10-27'),by=1),"%a"))
dfr$week <- strftime(dfr$date,format="%V")
dfr$week <- factor(dfr$week,levels=rev(unique(dfr$week)))
dfr$month <- factor(strftime(dfr$date,format="%B"),levels=unique(format(seq(as.Date('2019-01-01'),as.Date('2019-12-31'),by=1),"%B")))
dfr$ddate <- factor(strftime(dfr$date,format="%d"))

ggplot(dfr,aes(x=day,y=week))+
  geom_tile(fill="grey80")+
  geom_text(aes(label=ddate))+
  scale_fill_manual(values=c("#8dd3c7","#ffffb3","#fb8072","#d3d3d3"))+
  facet_wrap(~month,ncol=1,scales="free_y")+
  scale_x_discrete(position="top")+
  #scale_y_reverse()+
  labs(x="",y="Week")+
  theme_bw(base_size=10)+
  theme(legend.title=element_blank(),
        panel.grid=element_blank(),
        panel.border=element_blank(),
        axis.ticks=element_blank(),
        strip.background=element_blank(),
        legend.position="top",
        legend.justification="right",
        legend.direction="horizontal",
        legend.key.size=unit(0.3,"cm"),
        legend.spacing.x=unit(0.2,"cm"))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants