Skip to content

Instantly share code, notes, and snippets.

@tanyuan
Last active January 23, 2017 16:14
Show Gist options
  • Save tanyuan/d8020a6c257131f4a9509dc6fd2140a3 to your computer and use it in GitHub Desktop.
Save tanyuan/d8020a6c257131f4a9509dc6fd2140a3 to your computer and use it in GitHub Desktop.
Basic R plotting from a text file
# Read arguments from bash command line, example: Rscript data.txt plot.pdf
args <- commandArgs(trailingOnly = TRUE)
# Read data (space separated), if no header: header = FALSE
data <- read.csv(args[1], sep="")
# Set pdf output filename
pdf(file=args[2])
# Plot line plot
plot(data$time, data$raw, type='l')
# Draw another line on the same plot
lines(data$time, data$filtered, type = 'l', color='red')
# Draw points (.) on the same plot
points(data$time, data$points, pch='.', color='blue')
# Draw another line vertical/horizontal line on the same plot
abline(v=0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment