Rã§æ¸ããã2012ã«ã¬ã³ãã¼ã®ä¸èº«
ã¯ããã«
æè¿Rè¨èªã«ã¤ãã¦èª¿ã¹ã¦ãã¦CalendaR 2012 with ggplot2ã¨ããè¨äºãè¦ã¤ãã¾ããï¼ã©ããã£ãããããªãã¨ãã§ããã®ãããããªãã£ãã®ã§ä¸èº«ã追ãããã¦ã¿ãã¡ã¢ã§ãï¼
è¡ãã¨ã®è§£èª¬
library(ggplot2) year <- 2012
ggplot2ã¨ããç»åã©ã¤ãã©ãªãå¼ã³è¾¼ãã§ï¼å¤æ°yearã«2012ãã»ãããã¦ãã¾ãï¼ããã¯ç°¡åï¼
d <- seq.Date(as.Date(paste(year, "-01-01", sep = "")), as.Date(paste(year, "-12-31", sep = "")), by="days") z <- data.frame(Y = format(d, "%Y"), M = as.numeric(format(d, "%m")), D = as.numeric(format(d, "%d")), W = format(d, "%w"))
dã«"2012-01-01"ãã"2012-12-31"ã¾ã§ã®Dateãªãã¸ã§ã¯ãã®ã·ã¼ã±ã³ã¹ãä½ãã¾ãï¼zã«ã¯å¹´ï¼æï¼æ¥ï¼ææ¥ãä¸ã¤ã®è¦ç´ ã¨ãããã¼ã¿ãã¬ã¼ã ãä½ã£ã¦ãã¾ãï¼ããããã®å é äºã¤ã®ãã¼ã¿ã¯ä»¥ä¸ã®ããã«ãªã£ã¦ãã¾ãï¼
> d[1] [1] "2012-01-01" > d[2] [1] "2012-01-02" > z[1,] Y M D W 1 2012 1 1 0 > z[2,] Y M D W 2 2012 1 2 1
ã«ã¬ã³ãã¼ã«ä½¿ããã¼ã¿ã¯ããã ãã§ï¼å¾ã¯å³ç¤ºããããã®ããã¿ã§ãï¼
c <- ggplot(z, aes(D, M))
zãªãã¸ã§ã¯ãã®ãã¼ã¿ã横軸ãæ¥(D)ï¼ç¸¦è»¸ãæ(M)ã§è¡¨ç¤ºãã宣è¨ï¼
c + geom_text(aes(label=z$D, colour=factor(W), size = 20))
æ¥(z$D)ãã©ãã«ã¨ãã¦ææ¥(W)ã«åºã¥ããè²ã使ãã¾ãï¼ãµã¤ãºã¯20ï¼ãï¼åä½ã¯ä½ã ããï¼
+ scale_colour_manual(values = c("magenta", rep("black", 5),"darkturquoise"))
æ¥ææ¥(0)ããã¸ã§ã³ã¿ï¼ææããéæã¾ã§ã®5æ¥éã¯é»ï¼åæã¯ãã¼ã¯ã¿ã¼ã³ã¤ãºï¼
+ scale_y_continuous(trans = "reverse", breaks = 1:12)
é常ã ã¨ç¸¦è»¸ãä¸ãã1,2,3ã«ãªãã®ã§ï¼ã«ã¬ã³ãã¼ã¨ãã¦ä½¿ãããã«ä¸ãã1,2,3ã«ãªãããã«ãã¦ãï¼
+ labs(x="", y="") + opts(title = paste("CalendaR", year, "\n", sep = " "), plot.title = theme_text(colour = "black"), legend.position = "none" )
縦横ã®ã©ãã«ãæ¶ãã¦ï¼è¡¨é¡ãä»ãã¦ï¼ææ¥ãã¨ã®è²ã®èª¬æãæ¶ãã¦ã(legend.position)ï¼
ãã¾ã
åã«èª¿ã¹ãã ãã§ã¯é¢ç½ããªãã®ã§ï¼ã«ã¬ã³ãã¼ã«ä¼æ¥ã追å ãã¦ã¿ã¾ããï¼Wã«ã¯ææ¥ã«ããã0ã6ã¾ã§ã®æ°åãå ¥ã£ã¦ããã®ã§ããï¼ä¼æ¥ç¨ã«7ã追å ãã¾ãï¼データフレームを置き換えるãåèã«ãã¾ããï¼
levels(z$W)<-c(levels(z$W),7) z[z$Y==2012 & z$M==1 & z$D==1,]<-list(2012,1,1,7) z[z$Y==2012 & z$M==1 & z$D==2,]<-list(2012,1,2,7) z[z$Y==2012 & z$M==1 & z$D==9,]<-list(2012,1,9,7) z[z$Y==2012 & z$M==2 & z$D==11,]<-list(2012,2,11,7) z[z$Y==2012 & z$M==3 & z$D==20,]<-list(2012,3,20,7) z[z$Y==2012 & z$M==4 & z$D==29,]<-list(2012,4,29,7) z[z$Y==2012 & z$M==4 & z$D==30,]<-list(2012,4,30,7) z[z$Y==2012 & z$M==5 & z$D==3,]<-list(2012,5,3,7) z[z$Y==2012 & z$M==5 & z$D==4,]<-list(2012,5,4,7) z[z$Y==2012 & z$M==5 & z$D==5,]<-list(2012,5,5,7) z[z$Y==2012 & z$M==7 & z$D==16,]<-list(2012,7,16,7) z[z$Y==2012 & z$M==9 & z$D==17,]<-list(2012,9,17,7) z[z$Y==2012 & z$M==9 & z$D==22,]<-list(2012,9,22,7) z[z$Y==2012 & z$M==10 & z$D==8,]<-list(2012,10,8,7) z[z$Y==2012 & z$M==11 & z$D==3,]<-list(2012,11,3,7) z[z$Y==2012 & z$M==11 & z$D==23,]<-list(2012,11,23,7) z[z$Y==2012 & z$M==12 & z$D==23,]<-list(2012,12,23,7) z[z$Y==2012 & z$M==12 & z$D==24,]<-list(2012,12,24,7)
å¾ã¯è¡¨ç¤ºã®è²ãç´°å·¥ããã°å®æã§ãï¼
scale_colour_manual(values = c("magenta", rep("black", 5),"red","chocolate"))
åããã¦ã¿ãã¨ï¼ãããªã«ã¬ã³ãã¼ãã§ããããã¾ãï¼