knitr::opts_chunk$set(echo = TRUE) setwd("C:/Users/bai.li/Documents/StockSMARTVisualizer") devtools::load_all() setwd("C:/Users/bai.li/Documents/StockSMARTVisualizer/example/")
This is a map shows the LME around the U.S.. The GIS layer of the LME is downloaded from USGS database. For more details on the GIS files see https://www.sciencebase.gov/catalog/item/55c77722e4b08400b1fd8244.
library(rgdal) library(maps) library(mapdata) lme_spdf <- readOGR( dsn = file.path(getwd(), "data", "LME", "LMEs66.shp"), verbose = FALSE ) # The GIS files are downloaded from USGS: https://www.sciencebase.gov/catalog/item/55c77722e4b08400b1fd8244 lme_names <- lme_spdf$LME_NAME %in% lme_spdf$LME_NAME[c(60, 66, 4, 10, 25, 21, 12, 24, 28, 19, 20)] us_lme <- lme_spdf[lme_names, ] # png(file=file.path(getwd(), "LargeMarineEcosystemsMap.png"), # width=170, height=120, units="mm", res=1200) par(oma=c(0, 0, 0, 10)) plot(us_lme, col=rainbow(length(us_lme$LME_NAME)), xlim=c(-175, -60), ylim=c(-5, 73)) map("world", add=T, fill=T, col="gray90") points(coordinates(us_lme), pch=21, cex=3, bg="white") text(coordinates(us_lme), as.character(1:length(us_lme$LME_NAME))) degAxis(1) degAxis(2, las=2) box() legend(par('usr')[2], par('usr')[4], xpd=NA, title="Large Marine Ecosystems", paste0(1:length(us_lme$LME_NAME), ":", us_lme$LME_NAME, sep=""), cex=0.8, bty="n") # dev.off()
science_centers <- read.csv(file.path(getwd(), "data", "ScienceCentersLocation.csv")) # png(file=file.path(getwd(), "ScienceCenters.png"), # width=170, height=120, units="mm", res=1200) par(oma=c(0, 0, 0, 0)) plot(us_lme, col="lightblue", xlim=c(-170, -60), ylim=c(-5, 73)) map("world", add=T, fill=T, col="gray90") points(science_centers$Longitude, science_centers$Latitude, pch=16, cex=2, col="red") line_distance <- 20 for(i in 1:nrow(science_centers)){ if (science_centers$Science.Center[i] %in% c("PIFSC", "SWFSC")) { segments(x0=science_centers$Longitude[i], y0=science_centers$Latitude[i], x1=science_centers$Longitude[i]-line_distance, y1=science_centers$Latitude[i], col="red", lty=2) text(science_centers$Longitude[i]-line_distance*1.2, science_centers$Latitude[i]*1.05, science_centers$Science.Center[i], col="red") } if (science_centers$Science.Center[i] %in% c("NEFSC", "SEFSC")) { segments(x0=science_centers$Longitude[i], y0=science_centers$Latitude[i], x1=science_centers$Longitude[i]+line_distance, y1=science_centers$Latitude[i], col="red", lty=2) text(science_centers$Longitude[i]+line_distance*1.2, science_centers$Latitude[i]*1.05, science_centers$Science.Center[i], col="red") } if (science_centers$Science.Center[i] %in% c("NWFSC")) { segments(x0=science_centers$Longitude[i], y0=science_centers$Latitude[i], x1=science_centers$Longitude[i]-line_distance, y1=science_centers$Latitude[i]-line_distance/3, col="red", lty=2) text((science_centers$Longitude[i]-line_distance)*1.05, (science_centers$Latitude[i]-line_distance/3)*1.05, science_centers$Science.Center[i], col="red") } if (science_centers$Science.Center[i] %in% c("AFSC")) { segments(x0=science_centers$Longitude[i], y0=science_centers$Latitude[i], x1=science_centers$Longitude[i]-line_distance, y1=science_centers$Latitude[i]+line_distance/3, col="red", lty=2) text((science_centers$Longitude[i]-line_distance)*1.05, (science_centers$Latitude[i]+line_distance/3), science_centers$Science.Center[i], col="red") } } degAxis(1) degAxis(2, las=2) box() # dev.off()
raw_data <- read_stocksmart_data( filedir = system.file("extdata", package="StockSMARTVisualizer"), filename = "Current_SIS_Records.csv" ) model_names <- find_model_names(data=raw_data, model=c("AMAK", "ASAP", "BAM", "SS")) # model_names$amak id <- c(9, 15) data <- standardize_model_names(data=raw_data, model="AMAK", names=model_names$amak[id]) # model_names$asap id <- c(4, 14) data <- standardize_model_names(data=data, model="ASAP", names=model_names$asap[id]) # model_names$bam id <- c(1, 4, 6, 7) data <- standardize_model_names(data=data, model="BAM", names=model_names$bam[id]) # model_names$ss id <- c(2, 5, 6, 8:11, 13, 19: 22, 24, 26, 27, 28, 29) data <- standardize_model_names(data=data, model="SS", names=model_names$ss[id]) summary(as.factor(data$Assessment.Model.Standardize))
# png(file=file.path(getwd(), "AssessmentModel.png"), # width=170, height=120, units="mm", res=1200) key_model <- c("AMAK", "ASAP", "BAM", "SS") subdata <- data[(data$Assessment.Model.Standardize %in% key_model),] barplot_data <- as.matrix(table(subdata$Science.Center, subdata$Assessment.Model.Standardize)) science_centers <- read.csv(file.path(getwd(), "data", "ScienceCentersLocation.csv")) # png(file=file.path(getwd(), "ScienceCenters.png"), # width=170, height=120, units="mm", res=1200) par(oma=c(0, 0, 0, 0)) plot(us_lme, col="lightblue", xlim=c(-170, -60), ylim=c(-5, 73)) map("world", add=T, fill=T, col="gray90") points(science_centers$Longitude, science_centers$Latitude, pch=16, cex=2, col="red") line_distance <- 20 col <- c("orange", "green", "red", "deepskyblue3") barwidth=3 maxheight=3 for(i in 1:nrow(science_centers)){ if (science_centers$Science.Center[i] %in% c("PIFSC", "SWFSC")) { segments(x0=science_centers$Longitude[i], y0=science_centers$Latitude[i], x1=science_centers$Longitude[i]-line_distance, y1=science_centers$Latitude[i], col="red", lty=2) text((science_centers$Longitude[i]-line_distance)*1.05, science_centers$Latitude[i]*1.05, science_centers$Science.Center[i], col="red") plot_floating_bars(x=barplot_data[science_centers$Science.Center[i],], xllc=science_centers$Longitude[i]-line_distance*1.2, yllc=science_centers$Latitude[i]*0.8, col=col) } if (science_centers$Science.Center[i] %in% c("NEFSC", "SEFSC")) { segments(x0=science_centers$Longitude[i], y0=science_centers$Latitude[i], x1=science_centers$Longitude[i]+line_distance, y1=science_centers$Latitude[i], col="red", lty=2) text((science_centers$Longitude[i]+line_distance)*1.05, science_centers$Latitude[i]*1.05, science_centers$Science.Center[i], col="red") plot_floating_bars(x=barplot_data[science_centers$Science.Center[i],], xllc=(science_centers$Longitude[i]+line_distance)*1.06, yllc=science_centers$Latitude[i]*0.9, col=col) } if (science_centers$Science.Center[i] %in% c("NWFSC")) { segments(x0=science_centers$Longitude[i], y0=science_centers$Latitude[i], x1=science_centers$Longitude[i]-line_distance, y1=science_centers$Latitude[i]-line_distance/3, col="red", lty=2) text((science_centers$Longitude[i]-line_distance)*1.05, (science_centers$Latitude[i]-line_distance/3)*1.05, science_centers$Science.Center[i], col="red") plot_floating_bars(x=barplot_data["NWFSC / SWFSC",], xllc=(science_centers$Longitude[i]-line_distance)*1.2, yllc=(science_centers$Latitude[i]-line_distance/3)*0.8, col=col) } if (science_centers$Science.Center[i] %in% c("AFSC")) { segments(x0=science_centers$Longitude[i], y0=science_centers$Latitude[i], x1=science_centers$Longitude[i]-line_distance, y1=science_centers$Latitude[i]+line_distance/3, col="red", lty=2) text((science_centers$Longitude[i]-line_distance)*1.05, (science_centers$Latitude[i]+line_distance/3), science_centers$Science.Center[i], col="red") plot_floating_bars(x=barplot_data[science_centers$Science.Center[i],], xllc=(science_centers$Longitude[i]-line_distance)*1.2, yllc=(science_centers$Latitude[i]+line_distance/3)*0.9, col=col) } } legend("bottomleft", pch=22, col="black", pt.bg=col, legend=key_model, bty="n") degAxis(1) degAxis(2, las=2) box() # dev.off()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.