{"id":20081110,"url":"https://github.com/trangdata/ims-viz","last_synced_at":"2026-06-09T00:32:13.713Z","repository":{"id":95112843,"uuid":"400541833","full_name":"trangdata/ims-viz","owner":"trangdata","description":null,"archived":false,"fork":false,"pushed_at":"2021-08-30T22:23:06.000Z","size":350,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-02T13:27:59.992Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/trangdata.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-08-27T14:47:21.000Z","updated_at":"2021-08-30T22:23:08.000Z","dependencies_parsed_at":"2023-05-26T18:15:15.103Z","dependency_job_id":null,"html_url":"https://github.com/trangdata/ims-viz","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/trangdata/ims-viz","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trangdata%2Fims-viz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trangdata%2Fims-viz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trangdata%2Fims-viz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trangdata%2Fims-viz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/trangdata","download_url":"https://codeload.github.com/trangdata/ims-viz/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trangdata%2Fims-viz/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34086664,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-08T02:00:07.615Z","response_time":111,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T15:33:33.099Z","updated_at":"2026-06-09T00:32:13.699Z","avatar_url":"https://github.com/trangdata.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\"\n)\n```\n\n# Choosing colors for your chart\n\n\u003c!-- badges: start --\u003e\n\u003c!-- badges: end --\u003e\n\nSome R code I used to generate two charts of median age and [Tree City USA](https://www.arborday.org/programs/treecityusa/) for the Carteret County, NC.\nThese figures were used in my [talk](https://slides.com/trang1618/ims-viz/) at the Institute of Marine Sciences at UNC Chapel Hill.\n\nAdditional scratch R scripts can be ignored.\n\n## Load in packages\n\nShout out to Kyle Walker for his work on the **{tidycensus}** R package.\nThis package makes it extremely easy to download census data (in just a few lines like below).\nKyle also just preprinted his book [_Analyzing US Census Data: Methods, Maps, and Models in R_](https://walker-data.com/census-r/).\nSee an overview of the book content [here](https://twitter.com/kyle_e_walker/status/1432357038772957189).\n\n```{r message=FALSE, warning=FALSE}\nlibrary(tidycensus)\nlibrary(tidyverse)\n```\n\nIf you would like to choose a different variable (of over 20,000 variables), you can use `load_variables()` and browse the resulting dataframe.\n\n```{r}\n# v17 \u003c- load_variables(2017, \"acs5\", cache = TRUE)\n# View(v17)\n```\n\n## Continuous example: Age\n\nWe use the sequential color palette _viridis_ for this:\n\n```{r carteret-age}\ncarteret_age_df \u003c- get_acs(\n  state = \"NC\", county = \"Carteret\", geography = \"tract\",\n  variables = \"B01002_001\", geometry = TRUE\n) \n\ncarteret_age \u003c- carteret_age_df %\u003e%\n  ggplot(aes(fill = estimate)) +\n  geom_sf(color = NA) +\n  coord_sf(crs = 26911) +\n  scale_fill_viridis_c(\n    option = \"D\",\n    direction = -1,\n    trans = \"reverse\"\n  ) +\n  labs(\n    title = \"Median age in Carteret County, North Carolina\",\n    subtitle = \"2015-2019 ACS for Census Tracts\",\n    fill = NULL\n  ) +\n  theme_void() +\n  theme(legend.key.height = unit(30, \"pt\"))\n\ncarteret_age\n```\n\n## Categorical example: Tree City USA\n\nThe census actually doesn't have this data.\nI had to browse the [Tree City USA participants map](https://www.ncforestservice.gov/Urban/tcusa_NC_Participants.asp) to see which cities/census tract that participated.\n\n```{r carteret-tree}\ncarteret_tree_df \u003c- carteret_age_df %\u003e%\n  mutate(tree = if_else(grepl(\"9710.02|9703.04\", NAME), \"Tree City USA\", \"Nope\"))\n\ncarteret_tree \u003c- carteret_tree_df %\u003e%\n  ggplot(aes(fill = fct_rev(tree))) +\n  geom_sf(color = NA) +\n  coord_sf(crs = 26911) +\n  scale_fill_manual(values = c(\"#778868\", \"#f6edbd\")) +\n  labs(\n    title = \"Tree Cities in Carteret County, North Carolina\",\n    subtitle = \"2015-2019 ACS for Census Tracts\",\n    fill = NULL\n  ) +\n  theme_void()\n\ncarteret_tree\n```\n\n## Save charts\n\nThese last two lines are not run in this README, but I wanted to point out that specifying height and width would allow you to control the relative size of text vs. graph.\n\n```{r save-charts}\n# ggsave(\"figs/carteret_age.png\", carteret_age, height = 4, width = 4.5)\n# ggsave(\"figs/carteret-tree.png\", carteret_tree, height = 4, width = 5)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrangdata%2Fims-viz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrangdata%2Fims-viz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrangdata%2Fims-viz/lists"}