Skip to content

Instantly share code, notes, and snippets.

@kchannell
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kchannell/794dfe1966bf52bbdb27 to your computer and use it in GitHub Desktop.
Save kchannell/794dfe1966bf52bbdb27 to your computer and use it in GitHub Desktop.
# Eliminate N/A values from data file
P <- na.omit(P[1:14])
# Eliminate mean max and min from data set
P <- P[1:114,]
# Store mean max min data in separate data set
P_data <- P[114:116,]
# Convert factors to numerics
P[,1]<-as.character(P[,1])
P[,1]<-as.numeric(P[,1])
# Eliminate N/A values from data file
P <- na.omit(P[1:14])
# Store mean max min data in separate data set
P_data <- P[114:116,]
# Eliminate mean max and min (aka: rows after 113) from data set
P <- P[1:113,]
# Convert factors to numerics
P[,1]<-as.character(P[,1]) # without this- years are converted to 1-114
P[,1]<-as.numeric(P[,1])
# plot Annual Precipitation
plot(year,ann,
type = "l",
#ylim = c(0, 1050),
main = 'Annual Lake Superior Basin Precipitation',
xlab = 'Year',
ylab = 'Precipitation(mm)',
col = "blue",
lwd = 2)
grid()
par(new = F)
# Plot Precip values
# jan
plot(year,jan,
type = "l",
main = 'Lake Superior Basin Precipitation by Month',
xlab = 'Year',
ylab = 'Precipitation(mm)',
col = "green",
lwd = 2)
grid()
par(new = T)
# feb
plot(year,feb,
type = "l",
axes = F,
xlab = 'Year',
ylab = 'Precipitation(mm)',
col = "magenta",
lwd = 2)
grid()
par(new = T)
# mar
plot(year,mar,
type = "l",
axes = F,
xlab = 'Year',
ylab = 'Precipitation(mm)',
col = "orange",
lwd = 2)
grid()
par(new = T)
# apr
plot(year,apr,
type = "l",
axes = F,
xlab = 'Year',
ylab = 'Precipitation(mm)',
col = "purple",
lwd = 2)
grid()
par(new = T)
# may
plot(year,may,
type = "l",
axes = F,
xlab = 'Year',
ylab = 'Precipitation(mm)',
col = "cyan",
lwd = 2)
grid()
par(new = T)
# jun
plot(year,jun,
type = "l",
axes = F,
xlab = 'Year',
ylab = 'Precipitation(mm)',
col = "coral",
lwd = 2)
grid()
par(new = F)
# Read xlsx file data + headers
P <- read.xlsx("Precip_Basin.xlsx", startRow = 4, header = TRUE, sep = ",", sheetName = 'SUP_mm')
# Read xlsx file data
P <- read.xlsx("Precip_Basin.xlsx", sheetName = 'SUP_mm')
# Set directory
setwd("~/1-R")
# install and load packages to read xlxs files
install.packages("xlsx")
library(xlsx)
# Assign variables
year <- P[,'Year']
jan <- P[,'JAN']
feb <- P[,'FEB']
mar <- P[,'MAR']
apr <- P[,'APR']
may <- P[,'MAY']
jun <- P[,'JUN']
ann <- P[,'Total']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment