# Rework of the blood pressure stats # Author: Rainer Koenig library(ggplot2) # for the graphical output library(reshape) # for the melt function call # extract the last num lines from the dataset get_latest <- function(data, num) { rows <- nrow(data) cols <- ncol(data) start <- rows - num +1; return( data[start:rows,0:cols] ) } # read the bloodpressure data from the file bp_data <- read.table("daten.txt", header=TRUE, sep=" ") bp_data$Timestamp <- strptime(paste(bp_data$Datum, bp_data$Zeit), "%d.%m.%y %H:%M") bp_data <- subset(bp_data, select=c(-Datum, -Zeit)) # get a selection of the latest 60 measures bp_latest <- get_latest(bp_data, 60) # transform the data to a long table bp_plotdata <- melt(bp_latest, id="Timestamp") plot_latest_lines <- ggplot(bp_plotdata, aes(x=Timestamp, y=value, colour=variable)) + geom_line() + geom_point() + ylab("Messwert") + xlab("Datum") + scale_colour_discrete(name="Messwert") + scale_y_continuous(breaks=seq(40,200,by=10)) + labs(title="Bludruck (letzte 60 Werte)") plot_scatter_all <- ggplot(bp_data, aes(x=Sys, y=Dia)) + geom_point(alpha=0.2) + stat_smooth(method=lm) + labs(title="Korrelation Sys/Dia Werte") plot_histogram_latest <- ggplot(bp_plotdata, aes(x=value)) + geom_histogram(fill="white", colour="black", binwidth=10) + facet_grid(variable ~ .) + xlab("Wert") + ylab("Anzahl") + labs(title="Histogramm der letzten 60 Messungen")