R version
version
## _
## platform x86_64-apple-darwin17.0
## arch x86_64
## os darwin17.0
## system x86_64, darwin17.0
## status
## major 4
## minor 0.3
## year 2020
## month 10
## day 10
## svn rev 79318
## language R
## version.string R version 4.0.3 (2020-10-10)
## nickname Bunny-Wunnies Freak Out
パッケージの有効化
library(ggplot2)
library(lubridate)
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
データの読み込みと数え上げ
the.all.data <- read.table("covid19.csv", header = TRUE, sep = ",")
the.date.positive <- table(the.all.data[,5])
データ保管用の日付のデータフレームの準備
the.date.array <- as.data.frame(seq(as.Date("2020-01-24"), as.Date("2020-12-30"), by="day"))
the.date.array[,2] <- c("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")[wday(the.date.array[,1])]
the.date.array[,2] <- factor(the.date.array[,2], levels = c("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"), ordered = TRUE)
データの結合とカラム名の設定
the.date.array[,3] <- the.date.positive[as.character(the.date.array[,1])]
the.date.array[,3] <- as.integer(the.date.array[,3])
the.date.array[is.na(the.date.array)] <- 0
colnames(the.date.array) <- c("Date", "Day", "Positive")
ggplot2でグラフ化
ggplot(the.date.array, aes(x=Date, y=Positive))+geom_bar(stat = "identity")+scale_x_date(date_labels="%Y/%m")+facet_wrap(~Day)