Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visualizations (Interactive) #22

Closed
Tracked by #32
andrewallenbruce opened this issue Oct 18, 2023 · 2 comments
Closed
Tracked by #32

Visualizations (Interactive) #22

andrewallenbruce opened this issue Oct 18, 2023 · 2 comments
Assignees
Labels
geospatial 🌎 map making , geocoding, etc. visualization 🎨

Comments

@andrewallenbruce
Copy link
Owner

Code

library(tictoc)
library(provider)
library(tidyverse)
library(highcharter)

tic()
rhc <- providers(specialty_code = "00-17")

#> # A tibble: 5,168 × 7
#>    npi       pac   enid  specialty_code specialty_description state organization
#>    <chr>     <chr> <chr> <chr>          <chr>                 <chr> <chr>       
#>  1 15088613… 0941… O200… 00-17          PART A PROVIDER - RU… WA    PALOUSE HEA…
#>  2 14978560… 0042… O200… 00-17          PART A PROVIDER - RU… ND    WEST RIVER …
#>  3 17605703… 0042… O200… 00-17          PART A PROVIDER - RU… ND    WEST RIVER …
#>  4 18019879… 0042… O200… 00-17          PART A PROVIDER - RU… SD    WEST RIVER …
#>  5 18312861… 0042… O200… 00-17          PART A PROVIDER - RU… ND    WEST RIVER …
#>  6 15583893… 0547… O200… 00-17          PART A PROVIDER - RU… ND    CARRINGTON …
#>  7 18018116… 0547… O200… 00-17          PART A PROVIDER - RU… ND    CARRINGTON …
#>  8 16694912… 0547… O200… 00-17          PART A PROVIDER - RU… ND    ST. JOSEPH'…
#>  9 18816228… 0244… O200… 00-17          PART A PROVIDER - RU… MI    PRESCOTT CL…
#> 10 11442076… 0648… O200… 00-17          PART A PROVIDER - RU… CA    MEDICAL OFF…
#> # ℹ 5,158 more rows

rhc_count <- rhc |> 
  count(state, 
        sort   = TRUE, 
        name   = "count") |> 
  mutate(state = campfin::expand_state(state),
         state = stringr::str_to_title(state))

#> # A tibble: 45 × 2
#>    state       count
#>    <chr>       <int>
#>  1 Kentucky      370
#>  2 Texas         332
#>  3 Missouri      326
#>  4 Tennessee     263
#>  5 Illinois      262
#>  6 California    252
#>  7 Mississippi   227
#>  8 Michigan      221
#>  9 Louisiana     214
#> 10 Iowa          209
#> # ℹ 35 more rows

hc <- rhc_count |>
  hchart("bar", 
         hcaes(x         = state, y = count), 
         color           = "#2980b9", 
         name            = "Rural Health Clinics") |>
  hc_yAxis(gridLineWidth = 0, 
           labels        = list(
           style         = list(color = "#000000")), 
           title         = list(
           text          = "", 
           style         = list(color = "#000000"))) |>
  hc_xAxis(labels        = list(style = list(color =  "#000000")), 
           title         = list(text= ""), 
           lineWidth     = 0, 
           tickWidth     = 0) |>
  hc_tooltip(useHTML     = TRUE, 
             crosshairs  = TRUE, 
             borderWidth = 1, 
             sort        = TRUE) |>
  hc_add_theme(hc_theme_bloom()) |>
  hc_plotOptions(column     = list(
                 dataLabels = list(enabled = TRUE))) |> 
  hc_title(
    text   = "Number of <b>Rural Health Clinics</b> <i>by State</i>",
    margin = 10,
    align  = "left",
    style  = list(color   = "#22A884", 
                  useHTML = TRUE)) |> 
  hc_size(height = 1000, 
          width  = 800)
toc()
#> 3.56 sec elapsed

Created on 2023-10-18 with reprex v2.0.2

Rplot

@andrewallenbruce andrewallenbruce added the presentation 📊 visualization or presentation related label Oct 18, 2023
@andrewallenbruce andrewallenbruce self-assigned this Oct 18, 2023
@andrewallenbruce
Copy link
Owner Author

Code

library(tictoc)
library(provider)
library(tidyverse)
library(highcharter)

tic()
rhc_abb <- providers(specialty_code = "00-17") |> 
  count(state, 
        sort = TRUE, 
        name = "count")

#> # A tibble: 45 × 2
#>    state count
#>    <chr> <int>
#>  1 KY      370
#>  2 TX      332
#>  3 MO      326
#>  4 TN      263
#>  5 IL      262
#>  6 CA      252
#>  7 MS      227
#>  8 MI      221
#>  9 LA      214
#> 10 IA      209
#> # ℹ 35 more rows

rhc_map <- hcmap(
  map = "countries/us/us-all",
  data = rhc_abb,
  value = "count",
  joinBy = c("hc-a2", "state"),
  name = "Rural Health Clinics",
  dataLabels = list(enabled = TRUE, format = "{point.name}"),
  borderColor = "#FAFAFA",
  borderWidth = 0.1,
  tooltip = list(
    valueSuffix = " RHCs")) |>
  hc_title(
    text = "Number of <b>Rural Health Clinics</b> <i>by State</i>",
    margin = 20,
    align = "left",
    style = list(color = "#22A884", useHTML = TRUE)) |> 
  hc_add_theme(hc_theme_bloom())
toc()
#> 4.14 sec elapsed

Created on 2023-10-18 with reprex v2.0.2

Rplot01

@andrewallenbruce
Copy link
Owner Author

Code

library(highcharter)
library(tidyverse)
library(provider)

ex <- gen_data(2020:2030) |> 
  change(pay) |> 
  dplyr::mutate(group = NULL) |> 
  dplyr::distinct(year, .keep_all = TRUE)

ex |> 
  hchart("column", 
  hcaes(x                   = year, 
        y                   = pay_chg), 
        name                = "Change") |> 
  hc_yAxis(gridLineWidth    = 0,
           labels           = list(
           style            = list(
           color            =  "#000000")),
           title            = list(text = "", 
           style            = list(
           color            = "#000000"))) |> 
  hc_xAxis(labels           = list(
           style            = list(
           color            =  "#000000")),
           title            = FALSE,
           lineWidth        = 0,
           tickWidth        = 0) |>  
  hc_title(text             = "Yearly Absolute Change") |> 
  hc_tooltip(useHTML        = TRUE,
             crosshairs     = TRUE,
             borderWidth    = 1,
             sort           = TRUE) |> 
  hc_plotOptions(column     = list(
                 color      = "red",
                 dataLabels = list(
                 enabled    = TRUE))) |> 
  hc_add_theme(hc_theme_smpl()) |> 
  hc_size(height = 500, width = 550)

Created on 2023-10-20 with reprex v2.0.2

@andrewallenbruce andrewallenbruce added the geospatial 🌎 map making , geocoding, etc. label Oct 24, 2023
@andrewallenbruce andrewallenbruce removed the presentation 📊 visualization or presentation related label Oct 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
geospatial 🌎 map making , geocoding, etc. visualization 🎨
Projects
None yet
Development

No branches or pull requests

1 participant