generated from SEFSC/SEFSC-Template
-
Notifications
You must be signed in to change notification settings - Fork 3
/
convert_csv_to_inddata.R
105 lines (72 loc) · 4.29 KB
/
convert_csv_to_inddata.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
rm(list = ls())
# devtools::install_github("mandykarnauskas/plotTimeSeries")
library(plotTimeSeries)
library(stringr)
# get list of data files and convert to indicatordata format ------------
setwd("C:/Users/mandy.karnauskas/Desktop/Caribbean-ESR/indicator_data")
filelis <- dir()[grep(".csv", dir())]
filelis[1:10]
for (i in 1:length(filelis)) {
setwd("../indicator_data")
d <- read.table(filelis[i], skip = 3, sep = ",", header = F)
d1 <- read.table(filelis[i], skip = 2, sep = ",", header = T)
if (class(d[,1]) == "factor" | class(d[,2]) == "factor") {
cat(filelis[i])
cat(" -file not in default format\n") } else {
cat(filelis[i])
cat(" ---------------------------------------- file ok\n")
nam <- unlist(strsplit(filelis[i], ".csv"))
if (length(grep("ulim", names(d1))) == 0) {
inddata <- conv2indicatordata(filelis[i], default = T) } else {
ll <- grep("llim", names(d1))
ul <- grep("ulim", names(d1))
inddata <- conv2indicatordata(filelis[i], default = F,
labrows = 1:3, datecols = 1,
indcols = apply(cbind(ll, ul), 1, min) - 1,
ulimcols = ul, llimcols = ll)
}
setwd("../indicator_objects")
save(inddata, file = paste0(unlist(strsplit(filelis[i], ".csv")), ".RData"))
}
}
# get list of indicatordata objects and generate plots -------------------
setwd("C:/Users/mandy.karnauskas/Desktop/Caribbean-ESR/indicator_objects")
lis <- dir()[grep(".RData", dir())]
lis
for (i in 1:length(lis)) {
setwd("../indicator_objects")
load(lis[i])
setwd("../indicator_plots")
if (length(inddata$datelist) < 10) {
plotIndicatorTimeSeries(inddata, coltoplot = 1:ncol(inddata$indicators), plotrownum = ncol(inddata$indicators),
sublabel = T, outtype = "png", CItype = "pts", type = "ptsOnly")
} else {
plotIndicatorTimeSeries(inddata, coltoplot = 1:ncol(inddata$indicators), plotrownum = ncol(inddata$indicators),
sublabel = T, dateformat = "%Y%B", outtype = "png") }
}
# replot with individual settings -----------------------------------------
setwd("../indicator_plots")
load("../indicator_objects/sargassum_innundation_monthly_mean_hu.RData")
plotIndicatorTimeSeries(inddata, coltoplot = 1, sublabel = T, CItype = "band", widadj = 2, type = "allLines",
dateformat = "%Y%B", outtype = "png")
load("../indicator_objects/beach_litter_un_carib.RData")
plotIndicatorTimeSeries(inddata, coltoplot = 1:ncol(inddata$indicators), plotcolnum = ncol(inddata$indicators),
sublabel = T, outtype = "png", CItype = "pts", type = "ptsOnly", widadj = 1.5)
load("../indicator_objects/NCRMP_coral_cover_richness.RData")
plotIndicatorTimeSeries(inddata, coltoplot = 1:ncol(inddata$indicators), plotcolnum = 3, plotrownum = 2,
sublabel = T, outtype = "png", CItype = "pts", type = "ptsOnly", widadj = 1.4)
load("../indicator_objects/hotel_occupancy_rates_USVI_and_PR.RData")
plotIndicatorTimeSeries(inddata, coltoplot = 1:ncol(inddata$indicators), plotrownum = 2, dateformat = "%Y%B",
sublabel = T, outtype = "png", widadj = 2.5, type = "allLines") #, anom = "stmon")
load("../indicator_objects/gdp_PR_and_USVI.RData")
plotIndicatorTimeSeries(inddata, coltoplot = 1:ncol(inddata$indicators), plotrownum = 2,
sublabel = T, outtype = "png", widadj = 2)
load("../indicator_objects/OceanNAICS.RData")
plotIndicatorTimeSeries(inddata, coltoplot = 1:ncol(inddata$indicators), plotcolnum = 4, plotrownum = 2,
sublabel = T, outtype = "png", widadj = 1.25, hgtadj = 1.3)
#load("../indicator_objects/PR_and_USVI_DHW-MonthlyMean.RData")
#plotIndicatorTimeSeries(inddata, coltoplot = 1:ncol(inddata$indicators), plotcolnum = ncol(inddata$indicators),
# sublabel = T, outtype = "png", CItype = "pts", type = "ptsOnly", widadj = 1.5, yposadj = 0.9)
load("../indicator_objects/Carib_SST.RData")
plotIndicatorTimeSeries(s, coltoplot = 1:3, plotrownum = 3, dateformat = "%m-%Y", sublabel = T,
trendAnalysis = T, widadj = 0.5, anom = "mon", type = "allLines", outtype = "png", hgtadj = 0.8)