Skip to content

Commit

Permalink
Clean up a few files whose latest versions didn't make it into the la…
Browse files Browse the repository at this point in the history
…st commit somehow.
  • Loading branch information
ekoski1 committed Mar 4, 2022
1 parent dd709f6 commit b9f5a7a
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 39 deletions.
16 changes: 4 additions & 12 deletions GHGsByCountyYeartabs.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ if (outputFormat == "pdf_document") {
align = c("lrrrrrrr"),
linesep =
if(Region == "New York State") {
c(rep.int(c(rep.int("", 4), "\\addlinespace"), (numberOfCounties - 1) %/% 5), "\\midrule")
c(rep.int(c(rep.int("", 4), "\\addlinespace"), (numberOfCounties) %/% 5),
rep.int("", (numberOfCounties - 1) %% 5),
"\\midrule")
} else {
c(rep.int("", numberOfCounties - 1), "\\midrule")
},
Expand All @@ -34,15 +36,5 @@ if (outputFormat == "pdf_document") {
kable_styling(latex_options = c("hold_position", "repeat_header"),
position = "center",
font_size = 10)
} # else { # HTML in case we ever use it.
# countiesGHGsummaryWidertab %>%
# kable(escape = FALSE, digits = 0, booktabs = TRUE,
# align = c("lrrrrrrr"),
# linesep = c("", "", "", "", "", "", "", "", "\\midrule"),
# caption = tableCaption(
# "Annual CO2-equivalent greenhouse gas emissions (metric tons) by county")) %>%
# kable_styling(bootstrap_options = c("hover", "condensed"),
# position = "center",
# font_size = 10)
# }
}

Binary file modified Generic-report-industry-and-agriculture.pdf
Binary file not shown.
23 changes: 19 additions & 4 deletions energyUsePerCountyYeartab.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,22 @@
energyUseSummaryWider <- pivot_wider(ungroup(energyUseSummary),
names_from = Year,
values_from = MMBTU) %>%
bind_rows(summarise_all(., ~(if(is.numeric(.)) sum(.) else "Totals"))) %>%
mutate(sum = rowSums(select(., starts_with("20")))) %>%
arrange(ifelse(Region == "New York State", desc(sum), sum)) %>%
mutate(sum = rowSums(select(., starts_with("20"))))

if (Region == "New York State") {
energyUseSummaryWider <- energyUseSummaryWider %>%
arrange(as.character(County))
} else {
energyUseSummaryWider <- energyUseSummaryWider %>%
arrange(sum)
}

energyUseSummaryWider <- energyUseSummaryWider %>%
bind_rows(summarise_all(., ~(if(is.numeric(.)) {
sum(.)
} else {
if (Region == "New York State") { "State" } else { "Region"}
}))) %>%
select(-sum)

# Convert numeric values to character, so we can use "," as a thousands separator.
Expand All @@ -34,7 +47,9 @@ if (outputFormat == "pdf_document") {
align = c("l", rep.int("r", (latestYear - earliestYear) + 1)),
linesep =
if(Region == "New York State") {
c(rep.int(c(rep.int("", 4), "\\addlinespace"), (numberOfCounties - 1) %/% 5), "\\midrule")
c(rep.int(c(rep.int("", 4), "\\addlinespace"), (numberOfCounties) %/% 5),
rep.int("", (numberOfCounties - 1) %% 5),
"\\midrule")
} else {
c(rep.int("", numberOfCounties - 1), "\\midrule")
},
Expand Down
2 changes: 1 addition & 1 deletion energyUsePerFuelYearplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ energyPerYearFuelPlot <- ggplot(RegionEnergyPerYearFuelBounds) +
"#ffe119", "#e6beff"),
name = "Fuel type",
# ... and order the legend keys the way we want them!
breaks = rev(str_replace_all(fuelNames, "_", " ")),
breaks = rev(fuelNames),
guide = guide_legend(override.aes = list(alpha = 0.6))) +
scale_y_continuous(labels = scientific_10) +
scale_x_continuous(breaks = seq(min(RegionEnergyPerYearFuel$YEAR),
Expand Down
4 changes: 2 additions & 2 deletions energyUsePerFuelYeartab.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ earliestRow <- filter(RegionEnergyPerYearFueltab, Year == min(Year))
latestRow <- filter(RegionEnergyPerYearFueltab, Year == max(Year))

firstNaturalGasPct <-
formatC(round(100 * (earliestRow$Natural_gas / earliestRow$`Annual totals`)),
formatC(round(100 * (earliestRow$`Natural gas` / earliestRow$`Annual totals`)),
format = "d")
lastNaturalGasPct <-
formatC(round(100 * (latestRow$Natural_gas / latestRow$`Annual totals`)),
formatC(round(100 * (latestRow$`Natural gas` / latestRow$`Annual totals`)),
format = "d")

RegionEnergyPerYearFueltab <- RegionEnergyPerYearFueltab %>%
Expand Down
13 changes: 3 additions & 10 deletions regionPlot1.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,7 @@
RegionEnergyPerNonMSector3dYearFuel <- RegionEnergyPerFuelYear_3dig %>%
filter((NAICS3dig < 300) | (NAICS3dig > 399)) %>%
group_by(YEAR, NAICSname3dig) %>%
summarize(Diesel = sum(Diesel, na.rm = TRUE),
LPG_NGL = sum(LPG_NGL, na.rm = TRUE),
Net_electricity = sum(Net_electricity, na.rm = TRUE),
Coal = sum(Coal, na.rm = TRUE),
Natural_gas = sum(Natural_gas, na.rm = TRUE),
Coke_and_breeze = sum(Coke_and_breeze, na.rm = TRUE),
Residual_fuel_oil = sum(Residual_fuel_oil, na.rm = TRUE),
Other = sum(Other, na.rm = TRUE),
summarize(across(all_of(fuelNames), ~sum(., na.rm = TRUE)),
.groups = "drop")

# Make our own copy of RegionEnergyPerNonMSector3dYearFuel with columns added
Expand Down Expand Up @@ -76,7 +69,7 @@ regionsNonM3dAreaPlot <- ggplot(RegionEnergyPerNonMSector3dYearFuelBounds) +
"#ffe119", "#e6beff"),
name = "Fuel type",
# ... and order the legend keys the way we want them!
breaks = rev(str_replace_all(fuelNames, "_", " ")),
breaks = rev(fuelNames),
guide = guide_legend(override.aes = list(alpha = 0.6))) +
scale_y_continuous(labels = scientific_10)

Expand All @@ -85,7 +78,7 @@ for (fuel in fuelNames) {
geom_ribbon(aes(YEAR,
ymin = !!as.symbol(str_c(fuel, "Lower")),
ymax = !!as.symbol(str_c(fuel, "Upper")),
fill = !!quo_name(str_replace_all(fuel, "_", " "))), alpha = 0.6)
fill = !!quo_name(fuel)), alpha = 0.6)
}

# Below doesn't seem to work -- why not?
Expand Down
13 changes: 3 additions & 10 deletions regionPlot2.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,7 @@
RegionEnergyPerMfgSector3dYearFuel <- RegionEnergyPerFuelYear_3dig %>%
filter((NAICS3dig > 299) & (NAICS3dig < 400)) %>%
group_by(YEAR, NAICS3dig, NAICSname3dig) %>%
summarize(Diesel = sum(Diesel, na.rm = TRUE),
LPG_NGL = sum(LPG_NGL, na.rm = TRUE),
Net_electricity = sum(Net_electricity, na.rm = TRUE),
Coal = sum(Coal, na.rm = TRUE),
Natural_gas = sum(Natural_gas, na.rm = TRUE),
Coke_and_breeze = sum(Coke_and_breeze, na.rm = TRUE),
Residual_fuel_oil = sum(Residual_fuel_oil, na.rm = TRUE),
Other = sum(Other, na.rm = TRUE),
summarize(across(all_of(fuelNames), ~sum(., na.rm = TRUE)),
.groups = "drop")

# Make our own copy of RegionEnergyPerMfgSector3dYearFuel with columns added
Expand Down Expand Up @@ -83,15 +76,15 @@ regionsMfg3dAreaPlot1 <- ggplot(RegionEnergyPerMfgSector3dYearFuelBounds1) +
"#ffe119", "#e6beff"),
name = "Fuel type",
# ... and order the legend keys the way we want them!
breaks = rev(str_replace_all(fuelNames, "_", " "))) +
breaks = rev(fuelNames)) +
scale_y_continuous(labels = scientific_10)

for (fuel in fuelNames) {
regionsMfg3dAreaPlot1 <- regionsMfg3dAreaPlot1 +
geom_ribbon(aes(YEAR,
ymin = !!as.symbol(str_c(fuel, "Lower")),
ymax = !!as.symbol(str_c(fuel, "Upper")),
fill = !!quo_name(str_replace_all(fuel, "_", " "))), alpha = 0.6)
fill = !!quo_name(fuel)), alpha = 0.6)
}

show(regionsMfg3dAreaPlot1)
Expand Down

0 comments on commit b9f5a7a

Please sign in to comment.