Skip to content

Commit 5664a13

Browse files
Merge pull request #21 from MitchellHarrison/tuesday
tidytuesday 01142025
2 parents 078563e + fd65ab2 commit 5664a13

51 files changed

Lines changed: 4485 additions & 3224 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"hash": "64ac6579e994377171f9038c67e2b9f5",
3+
"result": {
4+
"engine": "knitr",
5+
"markdown": "---\ntitle: \"Posit::Conf 2023 | TidyTuesday\"\nauthor: \"Mitchell Harrison\"\ndate: \"01/18/2025\"\ncategories:\n - \"Data Viz\"\n - \"TidyTuesday\"\nimage: \"../../images/thumbnails/projects/tidytuesday/01142025.png\"\n---\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(tidyverse)\nlibrary(lubridate)\nlibrary(ggthemes)\n\nconf23 <- read_csv(\"data/conf2023.csv\")\nconf24 <- read_csv(\"data/conf2024.csv\")\n\n#conf23 <- read_csv(\"projects/tidytuesday_01142025/data/conf2023.csv\")\n#conf24 <- read_csv(\"projects/tidytuesday_01142025/data/conf2024.csv\")\n```\n:::\n\n\n\n# The Viz\n\nHello all! This week's \n[TidyTuesday](https://github.com/rfordatascience/tidytuesday/blob/main/data/2025/2025-01-14/readme.md)\nbrings us the event schedule from the posit::conf events of 2023 and 2024.\nAlthough there isn't always much in the way of data analysis that we can do with\na simple list of conference events, I did find a phenomenon that amused me.\n\nAt the conference, there are three types of talks: keynote talks to open and\nclose both days of the conference, regular talks that occur during the day, and\nvery quick lightning talks that cover smaller topics in a very short time\nwindow. For some reason, all of the lightning talks were scheduled to overlap\nwith the only pharma-related main talks at the entire event. So people had to\nchoose whether to attend the pharma talks or the lightning talks. I'm not sure\nwhat the rationale for scheduling it that was is, but here's a plot to\ndemonstrate!\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nset.seed(103)\n\nnew_23 <- conf23 |>\n distinct(session_type, session_start, .keep_all = TRUE) |>\n mutate(\n session_start_time = format(session_start, \"%H:%M:%S\"),\n session_start_time = as.POSIXct(session_start_time, format = \"%H:%M:%S\"),\n session_end_time = session_start_time + minutes(session_length),\n date_encoded = if_else(session_date == min(session_date), 1, 2),\n session_date2 = if_else(session_date == as.POSIXct(\"2023-09-19\"), 0, 1)\n )\n\nlightning <- new_23 |>\n filter(session_type == \"lightning\")\n\nnon_lightning <- new_23 |>\n filter(session_type != \"lightning\")\n\nnew_23 |>\n ggplot(aes(color = session_type, x = session_start_time, y = session_date2)) + \n geom_jitter(data = lightning, size = 2, height = 0.1, width = 0) +\n geom_point(data = non_lightning, size = 3) +\n geom_segment(\n aes(xend = session_end_time),\n data = non_lightning,\n linewidth = 1.5\n ) +\n geom_rect(\n xmin = as.POSIXct(\"17:00:00\", format = \"%H:%M:%S\"),\n xmax = as.POSIXct(\"19:20:00\", format = \"%H:%M:%S\"),\n ymin = 0.33,\n ymax = 0.67,\n fill = \"#f0f0f0\", # theme background color\n color = NA\n ) +\n annotate(\n geom = \"text\",\n x = as.POSIXct(\"17:00:00\", format = \"%H:%M:%S\"),\n y = 0.5,\n label = paste(\n \"Lightning talks took place\\nexclusively during these\\nPharma-related\",\n \"main talks.\\nSorry, doc!\"\n ),\n hjust = \"left\",\n color = \"#016392\",\n fontface = \"bold\"\n ) +\n annotate(\n geom = \"segment\",\n x = as.POSIXct(\"16:20:00\", format = \"%H:%M:%S\"),\n xend = as.POSIXct(\"16:55:00\", format = \"%H:%M:%S\"),\n y = 0.14,\n yend = 0.34,\n color = \"#016392\",\n linewidth = 1\n ) +\n theme_fivethirtyeight() +\n scale_color_wsj() +\n scale_y_continuous(\n breaks = c(0, 1),\n labels = c(\"Sep 19\", \"Sep 20\")\n ) +\n labs(\n title = \"Event schedule - posit::conf(2023)\",\n subtitle = \"Hopefully there were no impatient pharmacists there.\",\n color = element_blank()\n )\n```\n\n::: {.cell-output-display}\n![](talks_files/figure-html/build-viz-1.png){width=672}\n:::\n:::\n\n\n\n# Challenges\n\nAlthough the plot is pretty simple, I used some non-intuitive techniques to\nplace the text and line annotations when the data are dates instead of regular\ncontinuous values. I encoded the `y` axis as a continuous one and used\n`POSIXct` objects to place them on the `x` axis. Feel free to check the code to\nsee how that worked!\n\n# Conclusion\n\nAs always, thanks for reading! Feel free to reach out to me on\n[LinkedIn](https://linkedin.com/in/harrisonme) if you want to connect or ask\nquestions about my work. See you next week!",
6+
"supporting": [
7+
"talks_files"
8+
],
9+
"filters": [
10+
"rmarkdown/pagebreak.lua"
11+
],
12+
"includes": {},
13+
"engineDependencies": {},
14+
"preserve": {},
15+
"postProcess": true
16+
}
17+
}
21 KB
Loading
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"hash": "44871f8a8326d36a594dfbe51205ca47",
3+
"result": {
4+
"engine": "knitr",
5+
"markdown": "---\ntitle: \"Our World in Emissions | TidyTuesday\"\nauthor: \"Mitch Harrison\"\ncategories:\n - \"Data Viz\"\n - \"TidyTuesday\"\nimage: \"../../images/thumbnails/projects/tidytuesday/05212024.png\"\n---\n\n\nHello, all! Welcome to TidyTuesday. This week, as climate analysts often do, we \nare going to get mildly depressing in pursuit of a pretty graph. This time, we \nwill look at emissions from various actors' coal, natural gas, and cement \nproduction. Spoiler: it's not good.\n\nThe data for this week are brought to us by \n[Carbon Majors](https://carbonmajors.org), \nwho have compiled a database going all the way back to the 1850's! The dataset \ncontains emission data for 75 state and non-state actors, but we will aggregate \ninto total emissions by type for the plot. If you want to get more granular in \nyour own plot, check out the data on the TidyTuesday GitHub repository \n[here](https://github.com/rfordatascience/tidytuesday/tree/master/data/2024/2024-05-21)! \n\n\n\n::: {.cell layout-align=\"center\"}\n\n```{.r .cell-code}\nlibrary(tidyverse)\n\n# read data and rename an ugly column ------------------------------------------\nemis<- read_csv(paste0(\n \"https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/\",\n \"data/2024/2024-05-21/emissions.csv\"\n )\n)\n\nemis <- emis |>\n rename(emissions = \"total_emissions_MtCO2e\")\n\n# constants for ease of code legibility ----------------------------------------\nLEVS <- c(\"Coal\", \"Oil & NGL\", \"Natural Gas\", \"Cement\")\nBG_COLOR <- \"#F0F0F0\"\nGRAY <- \"gray35\"\nUN_TEXT <- paste(\n \"In 1995, the United Nations\\nConference of the Parties met for\\nthe first\", \n \"time to discuss the looming\\nthreat of climate change. The COP\\nhas\",\n \"met twenty-eight times since.\"\n)\n\n# data cleanup -----------------------------------------------------------------\nemis |>\n filter(year >= 1900) |> # lots of near-zero space without this filter\n mutate(\n commodity = if_else(str_detect(commodity, \"Coal\"), \"Coal\", commodity),\n commodity = factor(commodity, levels = LEVS) # re-order areas\n ) |>\n group_by(year, commodity) |>\n summarise(emissions = sum(emissions), .groups = \"drop\") |>\n \n # start of plot --------------------------------------------------------------\n ggplot(aes(x = year, y = emissions, fill = commodity)) +\n geom_area(alpha = 0.9) +\n \n # UN COP annotation text box -------------------------------------------------\n annotate(\n geom = \"segment\",\n x = 1995,\n xend = 1995,\n y = 35500,\n yend = 20500,\n linetype = \"solid\",\n linejoin = \"round\",\n linewidth = 1,\n color = \"grey35\",\n arrow = arrow(type = \"closed\", length = unit(0.2, \"cm\"))\n ) +\n annotate(\n geom = \"rect\",\n xmin = 1950.5,\n xmax = 1993.5,\n ymin = 23500,\n ymax = 35800,\n fill = BG_COLOR\n ) +\n annotate(\n geom = \"text\",\n x = 1992,\n y = 30000,\n label = UN_TEXT,\n color = GRAY,\n fontface = \"italic\",\n hjust = \"right\"\n ) +\n \n # replace legend with annotation text ----------------------------------------\n annotate(\n geom = \"text\",\n color = \"white\",\n x = 2020,\n y = c(1000, 4700, 13000, 26000),\n label = c(\"Cement\", \"Natural Gas\", \"Oil & NGL\", \"Coal\"),\n hjust = \"right\",\n fontface = \"bold\"\n ) +\n \n # visual style elements (love you, ggthemes) ---------------------------------\n ggthemes::scale_fill_colorblind() +\n ggthemes::theme_fivethirtyeight() +\n \n # customize axis breaks and labels -------------------------------------------\n scale_x_continuous(breaks = seq(1900, 2020, 20)) +\n scale_y_continuous(\n breaks = seq(0, 40000, 5000), \n label = scales::label_number(scale = 1e-3, suffix = \"k\")\n ) +\n labs(\n x = element_blank(),\n y = latex2exp::TeX(\"Emissions ($MtCO_2e$)\"),\n title = \"Our World in Emissions\",\n subtitle = latex2exp::TeX(\n paste(\n \"Emissions are measured in Millions of Tons of $CO_2$ equivalent\",\n \"($MtCO_2e$)\"\n )\n ),\n caption = paste(\n \"Made with love by Mitch Harrison\",\n \" \",\n \"Source: Carbon Majors database and TidyTuesday\"\n )\n ) + \n \n # theme cleanup --------------------------------------------------------------\n geom_hline(yintercept = 0, linewidth = 0.7, color = GRAY) + # bold axis\n theme(\n legend.position = \"none\", # hide legend\n axis.title.y = element_text(size = 10),\n plot.background = element_rect(fill = BG_COLOR)\n ) \n```\n\n::: {.cell-output-display}\n![](emissions_files/figure-html/plt-final-1.png){fig-align='center' fig-alt='This plot is titled Our World in Emissions. It is an area plot that shows\nglobal emissions over time by type. The types are coal, natural gas,\ncement, and oil and NGL. The plot notes that in 1995, the UN first met to\ndiscuss the climate threat. The plot shows near-zero emissions from 1900 to\n1920, when a slow increase begins. From there, emission growth seems to be\nexponentially increasing, with no decline since the UN first met. Coal is\nthe largest emitter, then oil and NGL, then natural gas, and finally,\ncement.' width=768}\n:::\n:::\n\n::: {.cell}\n\n:::\n\n\n\nSo there she is! As we can see, the UN COP seems to be fighting an uphill \nbattle. Emissions are rising, but a good analyst must note the limitations of \nthe data. What jumps out to me is that renewables aren't listed here because \nit's only a graph of emissions. For all we know (from this graph), these \nemissions only produce a small portion of the world's energy, and we are arguing \nabout a couple of percentage points. Maybe we have defeated climate change after\nall!\n\nOf course, that's not the case, but proving that point will require outside \ndata. So, I welcome everyone reading to write a fuller report using more \nevidence. If nothing else, it would make for some fun data viz practice! \n\nIf you want a step-by-step guide to how I made this plot, there is a tutorial \npage [here](../../tutorials/tidytuesday_05212024.qmd), or even stop by my\n[Discord server](https://discord.gg/vF6W2bdKFH) and ask me! And, of course, \nif you appreciate my work enough to buy me a coffee, you can do so \n[here](https://buymeacoffee.com/mitchellharrison). \nThank you for reading, and see you next week!",
6+
"supporting": [
7+
"emissions_files"
8+
],
9+
"filters": [
10+
"rmarkdown/pagebreak.lua"
11+
],
12+
"includes": {},
13+
"engineDependencies": {},
14+
"preserve": {},
15+
"postProcess": true
16+
}
17+
}
58.3 KB
Loading

0 commit comments

Comments
 (0)