provider icon indicating copy to clipboard operation
provider copied to clipboard

Visualizations (Interactive)

Open andrewallenbruce opened this issue 1 year ago • 2 comments

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 avatar Oct 18 '23 19:10 andrewallenbruce

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 avatar Oct 18 '23 19:10 andrewallenbruce

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 avatar Oct 20 '23 08:10 andrewallenbruce