cart_polygon: Calculate coordinates of transformed polygons to make...

Description Usage Arguments Value Author(s) Examples

View source: R/qmap.R

Description

Based on the given sizes of polygons, this function calculates the transformed coordinates using the Rcartogram package.

Usage

1
2
cart_polygon(x, y, name, size, diffuse, nrow = 100, ncol = 100, blank.init = 0.8, 
    ...)

Arguments

x,y

the x and y coordinates of original polygons (polygons are separated by NA's)

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 NA's plus 1)

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 cartogram

Value

A data frame of two columns x and y (coordinates of transformed polygons)

Author(s)

Yihui Xie and Xiaoyue Cheng

Examples

 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

ggobi/cranvas documentation built on May 17, 2019, 3:10 a.m.