Last active
January 23, 2017 16:14
-
-
Save tanyuan/d8020a6c257131f4a9509dc6fd2140a3 to your computer and use it in GitHub Desktop.
Basic R plotting from a text file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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