diff --git a/.github/workflows/r_covidcast_ci.yml b/.github/workflows/r_covidcast_ci.yml index 2f171e8c..cce2983a 100644 --- a/.github/workflows/r_covidcast_ci.yml +++ b/.github/workflows/r_covidcast_ci.yml @@ -16,16 +16,16 @@ on: jobs: build: - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 defaults: run: working-directory: R-packages/covidcast/ strategy: matrix: - r-version: [3.6] + r-version: [4.0] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up R ${{ matrix.r-version }} uses: r-lib/actions/setup-r@v2 diff --git a/R-packages/covidcast/DESCRIPTION b/R-packages/covidcast/DESCRIPTION index 8d3ebfbf..7ac0e1e2 100644 --- a/R-packages/covidcast/DESCRIPTION +++ b/R-packages/covidcast/DESCRIPTION @@ -48,7 +48,7 @@ Description: Tools for Delphi's 'COVIDcast Epidata' API: data access, maps and mobility data, typically updated daily and at the county level. All data sources are documented at . -Depends: R (>= 3.5.0) +Depends: R (>= 4.0.0) License: MIT + file LICENSE Encoding: UTF-8 LazyData: true diff --git a/R-packages/covidcast/NEWS.md b/R-packages/covidcast/NEWS.md index e428486e..01a6622f 100644 --- a/R-packages/covidcast/NEWS.md +++ b/R-packages/covidcast/NEWS.md @@ -1,6 +1,6 @@ # covidcast 0.5.3 -To be released. +- Changes to be compatible with an upcoming release of ggplot2. - Package vignettes have been adjusted so they do not make requests to the COVIDcast API during CRAN check runs. This change only affects the package diff --git a/R-packages/covidcast/R/plot.R b/R-packages/covidcast/R/plot.R index 6661c19d..66cdad9a 100644 --- a/R-packages/covidcast/R/plot.R +++ b/R-packages/covidcast/R/plot.R @@ -311,16 +311,32 @@ plot_choro <- function(x, time_value = NULL, include = c(), range, geom_args$fill <- main_col geom_args$data <- main_df - back_main_layer <- do.call(ggplot2::geom_sf, geom_args) + back_main_layer <- if (nrow(main_df) > 0) { + do.call(ggplot2::geom_sf, geom_args) + } else { + ggplot2::geom_blank() + } geom_args$fill <- pr_col geom_args$data <- pr_df - back_pr_layer <- do.call(ggplot2::geom_sf, geom_args) + back_pr_layer <- if (nrow(pr_df) > 0) { + do.call(ggplot2::geom_sf, geom_args) + } else { + ggplot2::geom_blank() + } geom_args$fill <- hawaii_col geom_args$data <- hawaii_df - back_hawaii_layer <- do.call(ggplot2::geom_sf, geom_args) - geom_args$fill <- alaska_col + back_hawaii_layer <- if (nrow(hawaii_df) > 0) { + do.call(ggplot2::geom_sf, geom_args) + } else { + ggplot2::geom_blank() + } geom_args$data <- alaska_df - back_alaska_layer <- do.call(ggplot2::geom_sf, geom_args) + geom_args$fill <- alaska_col + back_alaska_layer <- if (nrow(alaska_df) > 0) { + do.call(ggplot2::geom_sf, geom_args) + } else { + ggplot2::geom_blank() + } # Create the choropleth colors for counties if (attributes(x)$metadata$geo_type == "county") { @@ -438,16 +454,32 @@ plot_choro <- function(x, time_value = NULL, include = c(), range, geom_args$fill <- main_col geom_args$data <- main_df - main_layer <- do.call(ggplot2::geom_sf, geom_args) + main_layer <- if (nrow(main_df) > 0) { + do.call(ggplot2::geom_sf, geom_args) + } else { + ggplot2::geom_blank() + } geom_args$fill <- pr_col geom_args$data <- pr_df - pr_layer <- do.call(ggplot2::geom_sf, geom_args) + pr_layer <- if (nrow(pr_df) > 0) { + do.call(ggplot2::geom_sf, geom_args) + } else { + ggplot2::geom_blank() + } geom_args$fill <- hawaii_col geom_args$data <- hawaii_df - hawaii_layer <- do.call(ggplot2::geom_sf, geom_args) + hawaii_layer <- if (nrow(hawaii_df) > 0) { + do.call(ggplot2::geom_sf, geom_args) + } else { + ggplot2::geom_blank() + } geom_args$fill <- alaska_col geom_args$data <- alaska_df - alaska_layer <- do.call(ggplot2::geom_sf, geom_args) + alaska_layer <- if (nrow(alaska_df) > 0) { + do.call(ggplot2::geom_sf, geom_args) + } else { + ggplot2::geom_blank() + } coord_layer <- do.call(ggplot2::coord_sf, coord_args) # For continuous color scale, create a legend layer @@ -467,9 +499,9 @@ plot_choro <- function(x, time_value = NULL, include = c(), range, hidden_layer <- ggplot2::geom_point(ggplot2::aes( x = .data$x, y = .data$x, color = .data$z), data = hidden_df, alpha = 0) - guide <- ggplot2::guide_colorbar(title = NULL, horizontal = TRUE, - barheight = legend_height, - barwidth = legend_width) + guide <- ggplot2::guide_colorbar(title = NULL, direction = "horizontal", + barheight = legend_height, + barwidth = legend_width) scale_layer <- ggplot2::scale_color_gradientn(colors = col_fun(d), limits = range(d), breaks = legend_breaks, @@ -490,11 +522,11 @@ plot_choro <- function(x, time_value = NULL, include = c(), range, ggplot2::aes(x = .data$x, y = .data$x, fill = .data$z), data = hidden_df, alpha = 0 ) - guide <- ggplot2::guide_legend(title = NULL, horizontal = TRUE, nrow = 1, - keyheight = legend_height, - keywidth = legend_width / n, - label.position = "bottom", label.hjust = 0, - override.aes = list(alpha = 1)) + guide <- ggplot2::guide_legend(title = NULL, direction = "horizontal", nrow = 1, + keyheight = legend_height, + keywidth = legend_width / n, + label.position = "bottom", label.hjust = 0, + override.aes = list(alpha = 1)) scale_layer <- ggplot2::scale_fill_manual(values = col, breaks = legend_breaks, labels = legend_labels, @@ -665,7 +697,7 @@ plot_bubble <- function(x, time_value = NULL, include = c(), range = NULL, # Warn if there's any missing locations if (any(map_df$back_color == missing_col)) { - warning("Bubble maps can be hard to read when there is missing data;", + warning("Bubble maps can be hard to read when there is missing data; ", "the locations without data are filled in gray.") } @@ -683,16 +715,32 @@ plot_bubble <- function(x, time_value = NULL, include = c(), range = NULL, geom_args$mapping <- ggplot2::aes(geometry=.data$geometry) geom_args$fill <- main_df$back_color geom_args$data <- main_df - main_layer <- do.call(ggplot2::geom_sf, geom_args) + main_layer <- if (nrow(main_df) > 0) { + do.call(ggplot2::geom_sf, geom_args) + } else { + ggplot2::geom_blank() + } geom_args$fill <- pr_df$back_color geom_args$data <- pr_df - pr_layer <- do.call(ggplot2::geom_sf, geom_args) - geom_args$fill <- hawaii_df$back_color + pr_layer <- if (nrow(pr_df) > 0) { + do.call(ggplot2::geom_sf, geom_args) + } else { + ggplot2::geom_blank() + } geom_args$data <- hawaii_df - hawaii_layer <- do.call(ggplot2::geom_sf, geom_args) - geom_args$fill <- alaska_df$back_color + geom_args$fill <- hawaii_df$back_color + hawaii_layer <- if (nrow(hawaii_df) > 0) { + do.call(ggplot2::geom_sf, geom_args) + } else { + ggplot2::geom_blank() + } geom_args$data <- alaska_df - alaska_layer <- do.call(ggplot2::geom_sf, geom_args) + geom_args$fill <- alaska_df$back_color + alaska_layer <- if (nrow(alaska_df) > 0) { + do.call(ggplot2::geom_sf, geom_args) + } else { + ggplot2::geom_blank() + } # Change geometry to centroids # Use centroid coordinates for plotting bubbles @@ -733,7 +781,7 @@ plot_bubble <- function(x, time_value = NULL, include = c(), range = NULL, # Create the scale layer labels <- round(breaks, legend_digits) - guide <- ggplot2::guide_legend(title = NULL, horizontal = TRUE, nrow = 1) + guide <- ggplot2::guide_legend(title = NULL, direction = "horizontal", nrow = 1) scale_layer <- ggplot2::scale_size_manual(values = sizes, breaks = breaks, labels = labels, drop = FALSE, guide = guide) diff --git a/R-packages/covidcast/inst/shapefiles/county.geojson.bz2 b/R-packages/covidcast/inst/shapefiles/county.geojson.bz2 index 26607953..db7fb903 100644 Binary files a/R-packages/covidcast/inst/shapefiles/county.geojson.bz2 and b/R-packages/covidcast/inst/shapefiles/county.geojson.bz2 differ