R语言绘制不同调色板的日历图4
#---------------------------------------------------------
library(dplyr)
dat17 <- filter(dat,Year==2017)[,c(1,2)]
dat17$month <- as.integer(strftime(dat17$date, '%m')) #月份
dat17$monthf<-factor(dat17$month,levels=as.character(1:12),
labels=c("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"),ordered=TRUE)
dat17$weekday<-as.integer(strftime(dat17$date, '%u'))#周数
dat17$weekdayf<-factor(dat17$weekday,levels=(1:7),
labels=(c("Mon","Tue","Wed","Thu","Fri","Sat","Sun")),ordered=TRUE)
dat17$yearmonth<- strftime(dat17$date, '%m%Y') #月份
dat17$yearmonthf<-factor(dat17$yearmonth)
dat17$week<- as.integer(strftime(dat17$date, '%W'))#周数
dat17<-dat17 %>% group_by(monthf)%>%mutate(monthweek=1+week-min(week))
dat17$day<-strftime(dat17$date, "%d")
ggplot(dat17, aes(weekdayf, monthweek, fill=ValueCol)) +
geom_tile(colour = "white") +
scale_fill_gradientn(colours=rev(brewer.pal(11,'Spectral')))+
geom_text(aes(label=day),size=3)+
facet_wrap(~monthf ,nrow=3) +
scale_y_reverse()+
xlab("Day") + ylab("Week of the month") +
theme(strip.text = element_text(size=11,face="plain",color="black"))

#---------------------------------------------------------
ggplot(dat17, aes(weekdayf, monthweek, fill=ValueCol)) +
geom_tile(colour = "white") +
scale_fill_gradientn(colours=rev(brewer.pal(11,'Set1')))+
geom_text(aes(label=day),size=3)+
facet_wrap(~monthf ,nrow=3) +
scale_y_reverse()+
xlab("Day") + ylab("Week of the month") +
theme(strip.text = element_text(size=11,face="plain",color="black"))

#---------------------------------------------------------
ggplot(dat17, aes(weekdayf, monthweek, fill=ValueCol)) +
geom_tile(colour = "white") +
scale_fill_gradientn(colours=rev(brewer.pal(11,'Set2')))+
geom_text(aes(label=day),size=3)+
facet_wrap(~monthf ,nrow=3) +
scale_y_reverse()+
xlab("Day") + ylab("Week of the month") +
theme(strip.text = element_text(size=11,face="plain",color="black"))

ggplot(dat17, aes(weekdayf, monthweek, fill=ValueCol)) +
geom_tile(colour = "white") +
scale_fill_gradientn(colours=rev(brewer.pal(11,'Set3')))+
geom_text(aes(label=day),size=3)+
facet_wrap(~monthf ,nrow=3) +
scale_y_reverse()+
xlab("Day") + ylab("Week of the month") +
theme(strip.text = element_text(size=11,face="plain",color="black"))

ggplot(dat17, aes(weekdayf, monthweek, fill=ValueCol)) +
geom_tile(colour = "white") +
scale_fill_gradientn(colours=rev(brewer.pal(11,'Paired')))+
geom_text(aes(label=day),size=3)+
facet_wrap(~monthf ,nrow=3) +
scale_y_reverse()+
xlab("Day") + ylab("Week of the month") +
theme(strip.text = element_text(size=11,face="plain",color="black"))

ggplot(dat17, aes(weekdayf, monthweek, fill=ValueCol)) +
geom_tile(colour = "white") +
scale_fill_gradientn(colours=rev(brewer.pal(11,'Dark2')))+
geom_text(aes(label=day),size=3)+
facet_wrap(~monthf ,nrow=3) +
scale_y_reverse()+
xlab("Day") + ylab("Week of the month") +
theme(strip.text = element_text(size=11,face="plain",color="black"))

ggplot(dat17, aes(weekdayf, monthweek, fill=ValueCol)) +
geom_tile(colour = "white") +
scale_fill_gradientn(colours=rev(brewer.pal(11,'Accent')))+
geom_text(aes(label=day),size=3)+
facet_wrap(~monthf ,nrow=3) +
scale_y_reverse()+
xlab("Day") + ylab("Week of the month") +
theme(strip.text = element_text(size=11,face="plain",color="black"))

ggplot(dat17, aes(weekdayf, monthweek, fill=ValueCol)) +
geom_tile(colour = "white") +
scale_fill_gradientn(colours=rev(brewer.pal(11,'Pastel1')))+
geom_text(aes(label=day),size=3)+
facet_wrap(~monthf ,nrow=3) +
scale_y_reverse()+
xlab("Day") + ylab("Week of the month") +
theme(strip.text = element_text(size=11,face="plain",color="black"))

ggplot(dat17, aes(weekdayf, monthweek, fill=ValueCol)) +
geom_tile(colour = "white") +
scale_fill_gradientn(colours=rev(brewer.pal(11,'Pastel2')))+
geom_text(aes(label=day),size=3)+
facet_wrap(~monthf ,nrow=3) +
scale_y_reverse()+
xlab("Day") + ylab("Week of the month") +
theme(strip.text = element_text(size=11,face="plain",color="black"))

开发工具:RStudio与Alt+A截屏工具
- 点赞
- 收藏
- 关注作者
评论(0)