Skip to content

Commit 371ca14

Browse files
authored
Merge pull request #194 from weecology/sfwbr
South Florida Wading Bird Report tables and figures [no version bump]
2 parents 377af8d + 382607a commit 371ca14

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

Reports/sfwbr_recovery_report.R

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
library(tidyr)
2+
library(dplyr)
3+
library(wader)
4+
library(ggplot2)
5+
library(rJava)
6+
library(xlsx)
7+
8+
report_year = 2024
9+
10+
wb <- createWorkbook()
11+
#--------------------
12+
# DEFINE CELL STYLES
13+
#--------------------
14+
# title and subtitle styles
15+
title_style <- CellStyle(wb) +
16+
Font(wb, heightInPoints = 12,
17+
name="Calibri",
18+
underline = 1)
19+
20+
subtitle_style <- CellStyle(wb) +
21+
Font(wb,
22+
name="Calibri",
23+
heightInPoints = 10)
24+
25+
# data table styles
26+
cs <- CellStyle(wb) +
27+
Font(wb, heightInPoints=11, name="Calibri") +
28+
Alignment(horizontal = "ALIGN_CENTER")
29+
30+
rowname_style <- CellStyle(wb) +
31+
Font(wb, name = "Calibri") +
32+
Alignment(horizontal = "ALIGN_CENTER") +
33+
Border(position = c("RIGHT"),
34+
pen = c("BORDER_THIN"))
35+
36+
colname_style <- CellStyle(wb) +
37+
Font(wb, name = "Calibri") +
38+
Alignment(horizontal = "ALIGN_CENTER") +
39+
Border(position = c("TOP", "BOTTOM"),
40+
pen = c("BORDER_THIN"))
41+
42+
xlsx.addTitle <- function(sheet, rowIndex, title, titleStyle) {
43+
rows <- createRow(sheet, rowIndex = rowIndex)
44+
sheetTitle <- createCell(rows, colIndex = 1)
45+
setCellValue(sheetTitle[[1,1]], title)
46+
setCellStyle(sheetTitle[[1,1]], titleStyle)
47+
}
48+
49+
#### Get data ###
50+
51+
indicator_data <- max_count_indicator(maxyear = report_year) %>%
52+
filter(species %in% c("greg","sneg","whib","wost")) %>%
53+
pivot_wider(id_cols = year, names_from = species, values_from = count_mean) %>%
54+
mutate(across(2:5, \(x) round(x, 0))) %>%
55+
rename_with(toupper, .cols = -year)
56+
57+
#--------------------
58+
# BUILD WORKBOOK
59+
#--------------------
60+
61+
#### Build WCAS sheet ####
62+
maxcount <- createSheet(wb, sheetName = "Max Count")
63+
64+
xlsx.addTitle(sheet = maxcount, rowIndex = 1,
65+
title = paste("Three-year running averages of numbers of nesting pairs of Great Egrets, Snowy Egrets, White Ibises, and Wood Storks in the mainland Everglades (WCAs + ENP, not including Florida Bay) in ", report_year,".", sep=""),
66+
titleStyle = title_style)
67+
68+
addDataFrame(indicator_data, sheet = maxcount, startRow = 3, startColumn = 1,
69+
colnamesStyle = colname_style, colStyle = cs,
70+
rownamesStyle = rowname_style)
71+
72+
#### Write ####
73+
saveWorkbook(wb, file = 'Reports/recovery_report_table_2024.xlsx')
74+
75+
76+
### Write figures ####
77+
78+
# Do max count plot in Excel
79+
# max_count_plot(maxyear = report_year)
80+
# ggsave("my_plot.png", plot = my_plot, width = 6, height = 4, units = "in", dpi = 300)
81+
82+
coastal <- plot_coastal(maxyear = report_year)
83+
ggsave("coastal.png", plot = coastal, width = 6, height = 4, units = "in", dpi = 300)
84+
foraging <- plot_foraging(maxyear = report_year)
85+
ggsave("foraging.png", plot = foraging, width = 6, height = 4, units = "in", dpi = 300)
86+
initiation <- plot_initiation(maxyear = report_year)
87+
ggsave("initiation.png", plot = initiation, width = 6, height = 4, units = "in", dpi = 300)
88+
supercolony <- plot_supercolony(maxyear = report_year)
89+
ggsave("supercolony.png", plot = supercolony, width = 6, height = 4, units = "in", dpi = 300)
-44 KB
Binary file not shown.

0 commit comments

Comments
 (0)