Introduction
HealthDataScotland uses a R6 object to store and present spatial data associated with GP practices and hospitals across Scotland. This vignette will outline the functionality of these objects and the motivation behind their design.
Map objects
An R6 map object class is defined to store and present spatial data in HealthDataScotland. An example of this can be generated using example_map_unit().
map <- example_map_unit()
map
#> <map>
#> Public:
#> .id: map
#> .sf: sf, tbl_df, tbl, data.frame
#> .title: Interactive Map
#> clone: function (deep = FALSE)
#> id: function ()
#> initialize: function (.sf, .id = "map", .title = "Interactive Map")
#> plot: function (type, ...)
#> plot_data: function (type, ...)
#> plot_info: function (type, ...)
#> plot_types: function ()
#> server: function (data)
#> sf: function ()
#> title: function ()
#> ui: function (...)
#> validate: function ()
#> Private:
#> all_pin_ids: function ()
#> interactive_map: function (...)
#> interactive_map_data: function (ids = private[["all_pin_ids"]]())
#> interactive_map_info: function ()
#> pin_icon: function (type, ...)
#> required_sf_cols: function ()Data
map() objects store a sf data.frame object containing spatial data associated with health centres. This can be accessed using the $sf getter function.
map$sf()
#> Simple feature collection with 18 features and 2 fields
#> Geometry type: GEOMETRY
#> Dimension: XY
#> Bounding box: xmin: -8.650007 ymin: 54.63321 xmax: -0.7251864 ymax: 60.86076
#> CRS: NA
#> # A tibble: 18 × 3
#> ID type geometry
#> * <chr> <chr> <GEOMETRY>
#> 1 10002 gp POINT (-3.065759 56.49556)
#> 2 10017 gp POINT (-3.84469 56.37021)
#> 3 A101H hospital POINT (-5.115637 55.54328)
#> 4 A201H hospital POINT (-4.593139 55.43402)
#> 5 S08000015 board MULTIPOLYGON (((-5.118354 55.25852, -5.106465 55.25166, -…
#> 6 S08000016 board MULTIPOLYGON (((-2.865102 55.1352, -2.876198 55.14205, -2…
#> 7 S08000017 board MULTIPOLYGON (((-4.084061 54.76898, -4.082476 54.76524, -…
#> 8 S08000019 board MULTIPOLYGON (((-4.309941 56.51536, -4.29726 56.47488, -4…
#> 9 S08000020 board MULTIPOLYGON (((-2.271474 56.83238, -2.271474 56.83175, -…
#> 10 S08000022 board MULTIPOLYGON (((-5.572492 55.28654, -5.564566 55.28156, -…
#> 11 S08000024 board MULTIPOLYGON (((-3.3874 56.00091, -3.388192 56.00154, -3.…
#> 12 S08000025 board MULTIPOLYGON (((-2.908693 58.67529, -2.911071 58.67343, -…
#> 13 S08000026 board MULTIPOLYGON (((-1.650105 59.508, -1.650898 59.50676, -1.…
#> 14 S08000028 board MULTIPOLYGON (((-7.644247 56.79002, -7.6173 56.78816, -7.…
#> 15 S08000029 board MULTIPOLYGON (((-3.302596 56.03143, -3.293878 56.02894, -…
#> 16 S08000030 board MULTIPOLYGON (((-2.850836 56.97251, -2.8334 56.97687, -2.…
#> 17 S08000031 board MULTIPOLYGON (((-4.499363 56.06133, -4.504911 56.06756, -…
#> 18 S08000032 board MULTIPOLYGON (((-4.019864 56.02832, -4.030167 56.00963, -…Plotting
Visualising spaital data can be achieved using the $plot function with an appropriate type argument. To see which plot types are available to use, the $plot_types function can be used.
map$plot_types()
#> [1] "interactive_map"
map$plot(type = "interactive_map")Helper functions $plot_data and $plot_info can be used to create the data associated with each plot and character text describing each plot (alongside functionality related to the shiny application) respectively.
map$plot_data(type = "interactive_map")
#> Simple feature collection with 4 features and 2 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: -5.115637 ymin: 55.43402 xmax: -3.065759 ymax: 56.49556
#> CRS: NA
#> # A tibble: 4 × 3
#> ID type geometry
#> <chr> <chr> <POINT>
#> 1 10002 gp (-3.065759 56.49556)
#> 2 10017 gp (-3.84469 56.37021)
#> 3 A101H hospital (-5.115637 55.54328)
#> 4 A201H hospital (-4.593139 55.43402)
map$plot_info(type = "interactive_map")
#> [1] "This interactive map displays the locations of all available GP practices\n (blue pins) and hospitals (red pins) in Scotland. Pins can be selected to\n visualise individual GP practice or hospital data sets. Please note that\n some of the spatial data is several years old. Therefore this map\n may contain missing health centres."