Skip to content

Commit

Permalink
total project count as separate fig #3
Browse files Browse the repository at this point in the history
  • Loading branch information
fawda123 committed Dec 11, 2023
1 parent a4896c5 commit 3f375e1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 58 deletions.
65 changes: 16 additions & 49 deletions R/figs.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ levs <- c("Artificial Reefs", "Coastal Uplands", "Forested Freshwater Wetlands",
"Low-Salinity Salt Marsh", "Mangrove Forests", "Non-forested Freshwater Wetlands",
"Oyster Bars", "Salt Barrens", "Seagrasses", "Tidal Tributaries", "Uplands (Non-coastal)")

thm <- theme_minimal() +
theme(
legend.position = 'top',
axis.title.x = element_blank(),
panel.grid.minor.y = element_blank()
)

# cumulative projects, whole database ---------------------------------------------------------

# data prep
Expand All @@ -42,13 +49,6 @@ rstsum <- rstdatall %>%
cumtot = cumsum(tot)
)

thm <- theme_minimal() +
theme(
legend.position = 'top',
axis.title.x = element_blank(),
panel.grid.minor.y = element_blank()
)

toplo1 <- rstsum

p1 <- ggplot(toplo1, aes(x = Year, y = cumtot)) +
Expand Down Expand Up @@ -88,13 +88,6 @@ rstsum <- rstdatall %>%
) %>%
ungroup()

thm <- theme_minimal() +
theme(
legend.position = 'top',
axis.title.x = element_blank(),
panel.grid.minor.y = element_blank()
)

toplo1 <- rstsum

p1 <- ggplot(toplo1, aes(x = Year, y = cumtot, fill = Activity)) +
Expand Down Expand Up @@ -159,13 +152,6 @@ rstsum <- rstdatall %>%
) %>%
ungroup()

thm <- theme_minimal() +
theme(
legend.position = 'top',
axis.title.x = element_blank(),
panel.grid.minor.y = element_blank()
)

toplo1 <- rstsum
ncol <- length(levels(toplo1$Primary))

Expand Down Expand Up @@ -242,30 +228,12 @@ p1 <- ggplot(toplo1, aes(x = Year, y = tot, fill = Primary)) +
labs(
y = 'Projects',
fill = NULL,
)

p2 <- ggplot(toplo1, aes(x = Year, y = Acres, fill = Primary)) +
scale_x_continuous(breaks = seq(min(toplo1$Year), max(toplo1$Year))) +
geom_area(position = 'stack', alpha = 0.8) +
scale_fill_manual(values = colfun(ncol)) +
labs(
y = 'Acres',
fill = NULL,
)

p3 <- ggplot(toplo1, aes(x = Year, y = Miles, fill = Primary)) +
scale_x_continuous(breaks = seq(min(toplo1$Year), max(toplo1$Year))) +
geom_area(position = 'stack', alpha = 0.8) +
scale_fill_manual(values = colfun(ncol)) +
labs(
y = 'Miles',
fill = NULL,
)

pout <- p1 + p2 + p3 + plot_layout(ncol = 1, guides = 'collect') & thm & guides(fill = guide_legend(nrow = 5))
) +
thm +
guides(fill = guide_legend(nrow = 5))

png(here('docs/figs/totalhmp.png'), height = 8, width = 7, family = 'serif', units = 'in', res = 500)
print(pout)
png(here('docs/figs/totalhmp.png'), height = 3.75, width = 7, family = 'serif', units = 'in', res = 500)
print(p1)
dev.off()

# current totals bar --------------------------------------------------------------------------
Expand Down Expand Up @@ -306,7 +274,7 @@ toplo <- rstsum %>%
acreslab = gsub('\\.0$', '', acreslab)
)

thm <- theme_minimal() +
thm2 <- theme_minimal() +
theme(
panel.grid.minor = element_blank(),
panel.grid.major.y = element_blank(),
Expand All @@ -324,7 +292,7 @@ p1 <- ggplot(toplo, aes(x = tot, y = Primary, fill = Primary)) +
geom_text(aes(label = tot), hjust = 0, nudge_x = 0.5) +
scale_x_continuous(expand = c(0, 0), limits = c(0, max(toplo$tot) * 1.18)) +
scale_fill_manual(values = cols) +
thm +
thm2 +
labs(
y = NULL,
x = 'Total projects'
Expand All @@ -335,7 +303,7 @@ p2 <- ggplot(toplo, aes(x = Acres, y = Primary, fill = Primary)) +
geom_text(aes(label = acreslab), hjust = 0, nudge_x = 1000) +
scale_x_continuous(expand = c(0, 0), limits = c(0, max(toplo$Acres) * 1.55), labels = comma) +
scale_fill_manual(values = cols) +
thm +
thm2 +
theme(axis.text.y = element_blank()) +
labs(
y = NULL,
Expand All @@ -347,14 +315,13 @@ p3 <- ggplot(toplo, aes(x = Miles, y = Primary, fill = Primary)) +
geom_text(aes(label = round(Miles, 2)), hjust = 0, nudge_x = 0.005) +
scale_x_continuous(expand = c(0, 0), limits = c(0, max(toplo$Miles) * 1.3)) +
scale_fill_manual(values = cols) +
thm +
thm2 +
theme(axis.text.y = element_blank()) +
labs(
y = NULL,
x = 'Total Miles'
)


p <- p1 + p2 + p3 + plot_layout(ncol = 3)

png(here('docs/figs/curbar.png'), height = 5, width = 8, family = 'serif', units = 'in', res = 500)
Expand Down
Binary file modified docs/figs/totalhmp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 3f375e1

Please sign in to comment.