> last(dmdf,3)
01Hokkaido 02Aomori 03Iwate 04Miyagi 05Akita 06Yamagata 07Fukushima 08Ibaraki 09Tochigi 10Gunma 11Saitama 12Chiba 13Tokyo 14Kanagawa
477 4 0 0 1 0 0 1 0 1 2 1 7 6 6
478 3 2 1 0 0 0 0 0 0 0 1 5 6 2
479 7 0 1 2 0 1 1 0 0 0 2 1 3 4
15Niigata 16Toyama 17Ishikawa 18Fukui 19Yamanashi 20Nagano 21Gifu 22Shizuoka 23Aichi 24Mie 25Shiga 26Kyoto 27Osaka 28Hyogo 29Nara
477 0 1 1 0 0 2 1 1 3 1 3 0 50 39 4
478 0 0 4 0 0 0 0 0 2 0 0 2 41 6 0
479 0 0 1 0 0 0 0 0 5 0 0 0 19 8 0
30Wakayama 31Tottori 32Shimane 33Okayama 34Hiroshima 35Yamaguchi 36Tokushima 37Kagawa 38Ehime 39Kochi 40Fukuoka 41Saga 42Nagasaki
477 0 0 0 3 0 0 1 0 3 0 4 0 0
478 1 0 0 4 1 0 2 0 1 0 1 0 1
479 0 0 0 2 0 2 1 0 1 0 3 0 0
43Kumamoto 44Oita 45Miyazaki 46Kagoshima 47Okinawa t
477 1 0 0 0 1 2021-05-07
478 0 0 0 0 0 2021-05-08
479 0 0 0 0 0 2021-05-09
> head(w)
tokyo osaka hyogo t
400 11 2 1 2021-02-19
401 27 4 2 2021-02-20
402 17 1 0 2021-02-21
403 9 3 1 2021-02-22
404 11 5 3 2021-02-23
405 17 4 7 2021-02-24
> dplyr::filter(df,t > as.Date("2021-05-07"))
t variable value
1 2021-05-08 tokyo 6
2 2021-05-09 tokyo 3
3 2021-05-08 osaka 41
4 2021-05-09 osaka 19
5 2021-05-08 hyogo 6
6 2021-05-09 hyogo 8
w <- data.frame(tokyo=dmdf[,13],osaka=dmdf[,27],hyogo=dmdf[,28],t=dmdf$t)
w <- last(w,80)
df <-w %>% tidyr::gather(variable,value,-t) #exclude t to preserve time stamp or use "df <-w %>% tidyr::gather(variable,value,1:3)"
# df
p <- ggplot(df,aes(x=t, y=value, color=variable,fill=variable))
# p <- p+geom_histogram(stat = "identity",position = "stack")
p <- p+geom_bar(stat="identity",width=1,position = "dodge")
plot(p)
# end here
# if "df <-w %>% tidyr::gather(variable,value) #exclude t to preserve time stamp"
# 警告メッセージ:
# attributes are not identical across measure variables;
# they will be dropped
# see w[1:3,] contents are numeric and w$t is Date.
w <- data.frame(tokyo=dmdf[,13],osaka=dmdf[,27],hyogo=dmdf[,28],t=dmdf$t)
w <- last(w,80)
df <-w %>% tidyr::gather(variable,value,-t) #exclude t to preserve time stamp or use "df <-w %>% tidyr::gather(variable,value,1:3)"
# df
p <- ggplot(df,aes(x=t, y=value,fill=variable))
p <- p +scale_fill_brewer(palette="Accent")
p <- p+geom_bar(stat="identity",width=1,position = "dodge")
p <- p + theme(panel.background = element_rect(fill = "grey60",
colour = "lightblue"))
plot(p)
len <- 20
w <- data.frame(spx=as.vector(last(weeklyReturn(GSPC),len)),ndx=as.vector(last(weeklyReturn(NDX),len)),dji= as.vector(last(weeklyReturn(DJI),len)) ,t=index(last(weeklyReturn(GSPC),len)))
df <-w %>% tidyr::gather(index,weeklyreturn,-t)
df$t[len*seq(1,3,1)] <- df$t[dim(df)[1]-1]+7 # adjust each index's last entry. 3 came from gspc, ndx and di.
for(i in seq(1,len*3,1)){if((length(seq(as.Date("1970-01-05"),as.Date(df$t[i]),by='days'))%%7) != 5){df$t[i] <- df$t[i]+5-length(seq(as.Date("1970-01-05"),as.Date(df$t[i]),by='days'))%%7 }} # for the case national holiday distort date.
p <- ggplot(df,aes(x=t, y=weeklyreturn, color=index,fill=index))
p <- p + xlab("") + ylab("週間収益率")
# p <- p + geom_point(aes(y=case_per_capita,size=sign,color=r),alpha=1)
# p <- p+annotate("text",label=pref_db[,1],x=df[,2], y=df[,1]+0.1,colour='black',family = "HiraKakuProN-W3",size=3)
p <- p + theme_gray (base_family = "HiraKakuPro-W3")
p <- p + scale_color_brewer(name="指数",labels=c("ダウ30種","ナスダック","S&P500"),palette="Accent")
p <- p + scale_fill_brewer(name="指数",labels=c("ダウ30種","ナスダック","S&P500"),palette="Accent")
p <- p+geom_bar(stat="identity",width=7,position = "dodge")
plot(p)
0 件のコメント:
コメントを投稿