Description Usage Arguments Value Author(s) Examples
Based on the given sizes of polygons, this function calculates the transformed coordinates using the Rcartogram package.
1 2 | cart_polygon(x, y, name, size, diffuse, nrow = 100, ncol = 100, blank.init = 0.8,
...)
|
x,y |
the x and y coordinates of original polygons (polygons are
separated by |
name |
the names of original polygons |
size |
the size vector of polygons (length must be equal to the number
of polygons, i.e. the number of |
diffuse |
a positive value to control the diffusing/shrinking rate |
blank.init |
fill the NA's of the grids with blank.init * min(size) |
nrow,ncol |
numbers to define a grid for the cartogram algorithm (see references in Rcartogram); this can affect the convergence and speed of the algorithm, so may need to be adjusted for a few times |
... |
other arguments passed to |
A data frame of two columns x
and y
(coordinates of
transformed polygons)
Yihui Xie and Xiaoyue Cheng
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | library(cranvas)
## a simple example: two polygons of size 1 and 5 respectively
theta <- seq(0, 2 * pi, length = 100)
x <- c(cos(theta), NA, cos(theta) + 2)
y <- c(sin(theta), NA, sin(theta) + 1)
res <- cart_polygon(x, y, c("x", "y"), c(1, 5), diffuse = 100, nrow = 100, ncol = 100,
blank.init = 0.1)
plot(res$x, res$y, type = "n")
polygon(x, y)
text(c(0, 2), c(0, 1), c(1, 5)) # original polygons
polygon(res$x, res$y, border = "red", lty = 2, lwd = 2) # transformed polygons
## see map_qdata() for examples of real maps
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.