Graphing with R

From PeformIQ Upgrade
Revision as of 16:04, 17 September 2013 by PeterHarding (talk | contribs) (Created page with "=Processing Data on WIndows 7= I use the following BAT file to batch up R in a folder containing multiple data sets. <pre> @echo off set R_TERM="C:\Apps\R\R-3.0.1\bin\i386...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Processing Data on WIndows 7

I use the following BAT file to batch up R in a folder containing multiple data sets.


@echo off

set R_TERM="C:\Apps\R\R-3.0.1\bin\i386\Rterm.exe"

set FILES=*.csv

for %%F in (%FILES%) DO  (
    ECHO Processing %%F
    %R_TERM% --no-restore --no-save --args %%F < plot.r >  plot.out 2>&1
)

R Script File


args <- commandArgs(trailingOnly = TRUE)

print(args)

name <- args[1]

regexp <- "([^_]*)_([[:digit:]]{4})([[:digit:]]{2})([[:digit:]]{2}).*"

host <- sub(pattern=regexp, replacement="\\1", x=name)
year <- sub(pattern=regexp, replacement="\\2", x=name)
month <- sub(pattern=regexp, replacement="\\3", x=name)
day <- sub(pattern=regexp, replacement="\\4", x=name)

date <- sprintf("%s-%s-%s", year, month, day)

rm(args)

data_file <- sprintf("%s_%s%s%s.csv", host, year, month, day)

print(data_file)

data <- read.csv(data_file, header=T)


# data$Timestamp <- strptime(paste(data$Date, data$Time), "%Y-%m-%d %H:%M:%S")

data$Timestamp <- strptime(data$DateTime, "%Y-%m-%d %H:%M:%S")

title <- sprintf("%s - %s - %% CPU Utilization", date, host)

data$CPU <- data$User + data$System

print(title)

png(sprintf("%s_%s%s%s.png", host, year, month, day))

plot(data$Timestamp, data$CPU, main=title, type="h", col="light blue", xlab="Time", ylab="Ucpu%", lwd=1)

points(data$Timestamp, data$CPU, col="blue")

abline(h=mean(data$CPU), lty=2, col="red")

#s <- spline(data$CPU)

lines(smooth.spline(data$Timestamp, data$CPU, df = 10), lty = 3, col = "Dark Green")
#
#lines(s$x, s$y, type="b", pch=22, col="blue", lty=2)

dev.off()