mdsumner / ozmaps
Showing 1 of 12 files from the diff.

@@ -8,24 +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 -
#' @importFrom sf sf_extSoftVersion
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 32
28 -
  plot_sfc(x, add = add, ...)
33 +
34 +
  plot(sf::st_geometry(x), add = add, ..., reset = FALSE)
29 35
  invisible(x)
30 36
}
31 37
@@ -114,59 +120,3 @@
Loading
114 120
ozmap_abs_ste_data <- function(...){
115 121
 abs_ste
116 122
}
117 -
118 -
plot_bbox <- function(x, ...) {
119 -
  xr <- x[c("xmin", "xmax")]
120 -
  yr <- x[c("ymin", "ymax")]
121 -
  plot(xr, yr, type = "n", axes = FALSE, xlab = "", ylab = "", ...)
122 -
}
123 -
124 -
125 -
126 -
## from sf
127 -
# person(given = "Edzer",
128 -
#        family = "Pebesma",
129 -
#        role = c("ctb"),
130 -
#        comment = c(ORCID = "0000-0001-8049-7069"))
131 -
#' @importFrom graphics plot polypath
132 -
plot_sfc <- function(x, y, ..., lty = 1, lwd = 1, col = NA, border = 1, add = FALSE, rule = "evenodd") {
133 -
  # FIXME: take care of lend, ljoin, xpd, and lmitre
134 -
  stopifnot(missing(y))
135 -
  geom <- x[[attr(x, "sf_column")]]
136 -
  bb <- attr(geom, "bbox")
137 -
  ## stfusf
138 -
  prj <- attr(geom, "crs")[["proj4string"]]
139 -
  if (!"asp" %in% names(list(...))) {
140 -
    asp <- 1
141 -
    if (grepl("longlat", prj) || grepl("4326", prj)) {
142 -
      asp <- 1/cos(mean(bb[c("ymin", "ymax")]) * pi/180)
143 -
    }
144 -
  } else {
145 -
    asp <- list(...)$asp
146 -
  }
147 -
  if (! add)
148 -
    plot_bbox(bb, asp = asp)
149 -
  x <- geom
150 -
  lty = rep(lty, length.out = length(x))
151 -
  lwd = rep(lwd, length.out = length(x))
152 -
  col = rep(col, length.out = length(x))
153 -
  border = rep(border, length.out = length(x))
154 -
  #non_empty = ! st_is_empty(x)
155 -
  lapply(seq_along(x), function(i) {
156 -
      lapply(x[[i]], function(L) {
157 -
        polypath(sf_p_bind(L), border = border[i], lty = lty[i], lwd = lwd[i], col = col[i], rule = rule)
158 -
      })})
159 -
  invisible(NULL)
160 -
}
161 -
162 -
163 -
sf_p_bind <- function(lst) {
164 -
  if (length(lst) == 1)
165 -
    lst[[1]]
166 -
  else {
167 -
    ret = vector("list", length(lst) * 2 - 1)
168 -
    ret[seq(1, length(lst) * 2 - 1, by = 2)] = lst # odd elements
169 -
    ret[seq(2, length(lst) * 2 - 1, by = 2)] = NA  # even elements
170 -
    do.call(rbind, ret) # replicates the NA to form an NA row
171 -
  }
172 -
}
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