2018年2月20日火曜日

draw the graph to record blood pressure


# draw the graph data are picked up when above 101 to avoid anormaly.
#
plot(bp.xts[,-3][bp.xts$High > 101],col = c("red", "blue"),lwd=c(3,3,2,2),major.ticks='days',grid.ticks.on='days',type='p',ylim=c(60,160))
# draw a horizontal line at 130 as the benchmark
addSeries(xts(rep(130,length(index(bp.xts[bp.xts$High > 101]))),index(bp.xts[bp.xts$High > 101])),ylim=c(60,160),on=1,col=5,lwd=1)
# draw another line at 85.
addSeries(xts(rep(85,length(index(bp.xts[bp.xts$High > 101]))),index(bp.xts[bp.xts$High > 101])),ylim=c(60,160),on=1,col=5,lwd=1)
# add aux axis
axis(2,at=c(135,130,85))


#
# prepare xts data
#
# read data as csv format and convert to xts to plot
# bp <- read.csv("~/bp.csv")
bp <- read.csv("~/Downloads/bp - シート1.csv")
#
# remove the CSV file after the update
# don't use "~"  $HOME is okay R's "system" command is very awkward
# on this front.
#
system("rm \"$HOME/Downloads/bp - シート1.csv\"")
#
# below is also possible of course.
# system("rm \"/Users/honomoto/Downloads/bp - シート1.csv\"")
# while below is okay
system("rm ~/Downloads/bp*.csv")
# but ~ is not usable in "" as comma suppress meta character.
system("rm \"~/Downloads/bp - シート1.csv\"")

# create xts, remove data and time from the original and
# append POSIX time stamp.
bp.xts <- xts(bp[,c(-1,-2)],as.POSIXct(paste(bp$Date,bp$Time,sep=" ")))
# calculate weekly mean except the data of the sample whose $High is <=100
#
apply.weekly(bp.xts[bp.xts$High > 101],mean)

0 件のコメント: