mdsumner / ozmaps

@@ -8,23 +8,30 @@
Loading
8 8
#' See `abs_ste` for more detailed versions from the Australian Bureau of Statistics.
9 9
#' An example is 'abs_ste' which means 'State and Territory', and
10 10
#' so is a more detailed version of 'states'.
11 +
#'
12 +
#' `ozmap()` uses the sf package to plot, but does so by only plotting the
13 +
#' geometry rather than every colum, and leaves the plot region ready for overplotting with other
14 +
#' data.
11 15
#' @param x name of data set to use, default is `ozmap_country`
12 16
#' @param add add to existing plot, `FALSE` by default
13 17
#' @param ... arguments passed to ...
14 18
#' @seealso ozmap_data
15 19
#' @return the data set used, in 'sf' format
16 20
#' @export
17 -
#'
21 +
#' @importFrom sf st_geometry
22 +
#' @importFrom graphics plot
18 23
#' @examples
19 24
#' ozmap()
20 -
#' ozmap("country")
21 -
#' ozmap("abs_ced")  ## commonwealth (national) electoral divisions
25 +
#' ozmap("country", lwd = 6)
26 +
#' ozmap("abs_ced", add = TRUE, border = "firebrick")  ## commonwealth (national) electoral divisions
22 27
ozmap <- function(x = "states", ..., add = FALSE) {
23 28
  if ("states" %in% names(list(...))) {
24 29
    warning("states argument is deprecated, see 'oz::oz()' function")
25 30
  }
26 31
  x <- ozmap_data(x, quiet  = TRUE)
27 -
  plot_sfc(x, add = add, ...)
32 +
33 +
34 +
  plot(sf::st_geometry(x), add = add, ..., reset = FALSE)
28 35
  invisible(x)
29 36
}
30 37
@@ -113,58 +120,3 @@
Loading
113 120
ozmap_abs_ste_data <- function(...){
114 121
 abs_ste
115 122
}
116 -
117 -
plot_bbox <- function(x, ...) {
118 -
  xr <- x[c("xmin", "xmax")]
119 -
  yr <- x[c("ymin", "ymax")]
120 -
  plot(xr, yr, type = "n", axes = FALSE, xlab = "", ylab = "", ...)
121 -
}
122 -
123 -
124 -
125 -
## from sf
126 -
# person(given = "Edzer",
127 -
#        family = "Pebesma",
128 -
#        role = c("ctb"),
129 -
#        comment = c(ORCID = "0000-0001-8049-7069"))
130 -
#' @importFrom graphics plot polypath
131 -
plot_sfc <- function(x, y, ..., lty = 1, lwd = 1, col = NA, border = 1, add = FALSE, rule = "evenodd") {
132 -
  # FIXME: take care of lend, ljoin, xpd, and lmitre
133 -
  stopifnot(missing(y))
134 -
  geom <- x[[attr(x, "sf_column")]]
135 -
  bb <- attr(geom, "bbox")
136 -
  prj <- attr(geom, "crs")$proj4string
137 -
  if (!"asp" %in% names(list(...))) {
138 -
    asp <- 1
139 -
    if (grepl("longlat", prj) || grepl("4326", prj)) {
140 -
      asp <- 1/cos(mean(bb[c("ymin", "ymax")]) * pi/180)
141 -
    }
142 -
  } else {
143 -
    asp <- list(...)$asp
144 -
  }
145 -
  if (! add)
146 -
    plot_bbox(bb, asp = asp)
147 -
  x <- geom
148 -
  lty = rep(lty, length.out = length(x))
149 -
  lwd = rep(lwd, length.out = length(x))
150 -
  col = rep(col, length.out = length(x))
151 -
  border = rep(border, length.out = length(x))
152 -
  #non_empty = ! st_is_empty(x)
153 -
  lapply(seq_along(x), function(i) {
154 -
      lapply(x[[i]], function(L) {
155 -
        polypath(sf_p_bind(L), border = border[i], lty = lty[i], lwd = lwd[i], col = col[i], rule = rule)
156 -
      })})
157 -
  invisible(NULL)
158 -
}
159 -
160 -
161 -
sf_p_bind <- function(lst) {
162 -
  if (length(lst) == 1)
163 -
    lst[[1]]
164 -
  else {
165 -
    ret = vector("list", length(lst) * 2 - 1)
166 -
    ret[seq(1, length(lst) * 2 - 1, by = 2)] = lst # odd elements
167 -
    ret[seq(2, length(lst) * 2 - 1, by = 2)] = NA  # even elements
168 -
    do.call(rbind, ret) # replicates the NA to form an NA row
169 -
  }
170 -
}
Files Coverage
R 100.00%
Project Totals (2 files) 100.00%
1
comment: false
2

3
coverage:
4
  status:
5
    project:
6
      default:
7
        target: auto
8
        threshold: 1%
9
    patch:
10
      default:
11
        target: auto
12
        threshold: 1%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading