#' track my writing process
#' @param beginDate the begin date wanted to show
#' @param endDate the end date wanted to show
#' @return plots
#' @export
#' @examples
#' #track_my_writing()
#' #track_my_writing("2017-03-10","")
#'
#'
track_my_writing <- function(beginDate="2017-03-06",endDate="") {
## read the data
#data <- read.csv(file="~/Dropbox/org/my-write-tracks.csv",sep=",")
data <- read.table(file="~/Dropbox/my-write-tracks.txt",header = TRUE,sep=",")
data$date <- as.Date(data$date,format = "%Y-%m-%d")
data$week <- stringr::str_trim(data$week,side="both")
data$week <- factor(data$week,levels = c('周一',"周二","周三","周四","周五","周六","周日"))
# refine to time range
if (endDate ==""){
endDate <- max(data$date[])
}
df <- dplyr::filter(data,date >= beginDate & date <= endDate)
# plot
suppressWarnings(suppressPackageStartupMessages({
library(ggplot2)
}))
pl_words <- ggplot(df,aes(x=date,y= write.words)) + geom_bar(aes(fill= week),stat="identity")+
geom_text(aes(label=write.words)) + labs(x="日期", y= "写作字数") +
theme(text=element_text(family = "STKaiti",size=10))
## plot words
pl_goal <- ggplot(df,aes(x=date,y= goal)) + geom_point(aes(size=write.words,color=week))+
geom_text(aes(label=goal)) + labs(x="日期", y= "任务完成度") +
theme(text=element_text(family = "STKaiti",size=10))
week_words <- ggplot(df,aes(x=date,y= write.words)) +
geom_line() +
facet_wrap(~week) +
geom_text(aes(label=write.words)) +
labs(x="日期", y= "任务完成度") +
theme(text=element_text(family = "STKaiti",size=10))
return(list(df=data, plotwords=pl_words,plotgoal=pl_goal,weekgoal=week_words))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.