Skip to content

Commit

Permalink
minor changes in plots and tables.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmarch committed Apr 11, 2019
1 parent 86ae7bc commit 7d0091c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 15 deletions.
17 changes: 11 additions & 6 deletions 07_figures/plots_argo.R
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,18 @@ ggsave(p_png, p, width=25, height=14, units="cm", dpi=300)
# Plot 7: Coldspots
#------------------------------------------------

p <- plotrasterDis(r = coldspots, land = land.prj, box = box,
colors = c("1" = "#08519c"),
breaks = 1, legend.position = "none")

# Save as png file
# set output file and open device
p_png <- paste(fig_dir,"argo","coldspot.png", sep="/")
ggsave(p_png, p, width=25, height=14, units="cm", dpi=300)
png(p_png , width=25, height=14, units="cm", res=300)

# plot
plot(coldspots, col=c("#4393c3") , axes=FALSE, box=FALSE, legend=FALSE)
plot(coldspots_shp, col= "transparent", border= "grey40", lwd=0.01, add=TRUE) #border=NA
plot(land.prj, col= "grey80", border= "grey40", lwd=0.01, add=TRUE) #border=NA
plot(box, border= "grey70", add=TRUE)

# close device
dev.off()


#------------------------------------------------
Expand Down
20 changes: 14 additions & 6 deletions 07_figures/plots_eoo.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ library(raster)
library(rgdal)
library(ggplot2)
library(Hmisc)
library(data.table)
source("R/utils.R")
source("R/data_paths.R")

Expand All @@ -28,7 +29,8 @@ class <- unique(match$group) # get group classes
# Fig 1. Density maps of species subject to telemetry by taxonomic group.
#-------------------------------------------------------------------------
# Plot of number of species per taxa.

# Normalized from 0 to 1 in order to use the same color palette
range_list <- list()
for (i in 1:length(class)){

print(i)
Expand All @@ -37,14 +39,20 @@ for (i in 1:length(class)){
ncfile <- list.files(eoo_dir, pattern=paste0(class[i], ".nc"), full.names=TRUE)
nc <- raster(ncfile)

# Get min and max values per class
nc <- setMinMax(nc)
lim = data.frame(class=class[i], min=minValue(nc), max=maxValue(nc))
range_list[[i]] <- lim

# Plot
p <- plotraster(r = nc, land = land.prj, box = box, legendTitle = "No. species")
p <- plotraster(r = nc, land = land.prj, box = box, legendTitle = "")

# Save as png file
p_png = paste0(fig_dir, "/eoo/", class[i],".png")
ggsave(p_png, p, width=25, height=14, units="cm", dpi=300)
}

range <- rbindlist(range_list)
write.csv(range, paste0(fig_dir, "/eoo/", "ranges_per_taxa.csv"), row.names=FALSE)

#-------------------------------------------------------------------------
# Fig 2. Density maps of species subject to telemetry (all taxa)
Expand All @@ -66,16 +74,16 @@ for (i in 1:length(class)){
## Normalize from zero to one
nc <- setMinMax(nc)
norm <- (nc - minValue(nc)) / (maxValue(nc) - minValue(nc))
if (minValue(nc) == maxValue(nc)) norm <- nc # this exception applies for sirenians with max values = 1
rnorm <- stack(rnorm, norm)
}

## Average across taxa
allnorm <- mean(rnorm, na.rm=TRUE)
allnorm[allnorm == 0] <- NA

## Plot
legend <- paste0("All taxa \n (normalized)")
p <- plotraster(r = allnorm, land = land.prj, box = box, legendTitle = legend)
legend <- paste0("All taxa\n(normalized)\n")
p <- plotraster(r = allnorm, land = land.prj, box = box, lim=c(0,1), legendTitle = legend, legend.position = "bottom")

# Save as png file
p_png = paste0(fig_dir, "/eoo/", "alltaxa_normalized",".png")
Expand Down
2 changes: 1 addition & 1 deletion 07_figures/plots_overlap.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ for (i in 1:length(class)){
## Normalize number of species from zero to one
nc <- setMinMax(nc)
norm <- (nc - minValue(nc)) / (maxValue(nc) - minValue(nc))
if (minValue(nc) == maxValue(nc)) norm <- nc
if (minValue(nc) == maxValue(nc)) norm <- nc # this exception applies for sirenians with max values = 1

## Mask with coldspots
ov <- norm * coldspots # Mask for Argo undersampled areas
Expand Down
4 changes: 2 additions & 2 deletions 07_figures/plots_telemetry.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ pin <- raster(pin_dens)
#-------------------------------------------------------------------------

# Create plot
p <- plotraster(r = log10(chelo), land = land.prj, box = box,
legendTitle = expression(log[10]~(records / km^2)))
p <- plotraster(r = log10(chelo), land = land.prj, box = box, legend.position="bottom",
legendTitle = expression(log[10]~(observations / km^2)))

# Save as png file
p_png <- paste(fig_dir,"telemetry","turtle_telemetry_density.png", sep="/")
Expand Down
2 changes: 2 additions & 0 deletions 08_tables/tbl_taxonomic_groups.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ spp <- merge(match, eoo_overlap, by="taxonid")
df <- spp %>%
group_by (group_name) %>% #ISO_Ter1, Sovereign1
summarise (
# no. species
n = n(),
# exntent
meanExtent_km2 = mean(range_km2, na.rm=TRUE),
sdExtent_km2 = sd(range_km2, na.rm=TRUE),
Expand Down

0 comments on commit 7d0091c

Please sign in to comment.