## ----setup, include = FALSE--------------------------------------------------- knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.width = 6, fig.height = 4 ) library('orloca') ## ----------------------------------------------------------------------------- loca.p(c(0, 4, 2), c(0, 0, 2)) ## ----results = 'hide'--------------------------------------------------------- loca.p(x = c(0, 4, 2), y = c(0, 0, 2)) ## ----include = TRUE----------------------------------------------------------- loca.p(x = c(0, 4, 2), y = c(0, 0, 2), w = c(1, 1, 3), label = "Problem 1") ## ----include = FALSE---------------------------------------------------------- d <- data.frame(x = c(0, 10, 2), y = c(0, 0, 8), w = c(1, 3, 1)) ## ----------------------------------------------------------------------------- d ## ----------------------------------------------------------------------------- as(d, "loca.p") ## ----results = 'hide'--------------------------------------------------------- as.loca.p(d) ## ----------------------------------------------------------------------------- p1 <- loca.p(x = c(0, 4, 2), y = c(0, 0, 2), w = c(1, 1, 3), label = "Problem 1") as(p1, 'data.frame') ## ----results = 'hide'--------------------------------------------------------- as.data.frame(p1) ## ----------------------------------------------------------------------------- p1@label dp1 <- as.data.frame(p1) attr(dp1, "label") ## ----------------------------------------------------------------------------- set.seed(161236) rloca.p(5) ## ----------------------------------------------------------------------------- rloca.p(5, xmin = -1, xmax = 1, ymin = -5, ymax = 5, label = "Rectangle") ## ----------------------------------------------------------------------------- rloca.p(9, groups = 3, label = "Three equal group sizes") ## ----------------------------------------------------------------------------- rloca.p(groups = c(2, 2, 5), label = "Three unequal group sizes") ## ----------------------------------------------------------------------------- rl <- rloca.p(60, groups = 3, xmin = -1, xmax = 1, ymin = -1, ymax = 1, xgmin = -10, xgmax = 10, ygmin = -10, ygmax = 10, label = "Three groups") plot(rl) ## ----------------------------------------------------------------------------- summary(rl) ## ----------------------------------------------------------------------------- pt3 <- loca.p(x = c(0, 4, 2), y = c(0, 0, 2), label = "Three points") distsum(o = pt3, x = 3, y = 1) ## ----------------------------------------------------------------------------- distsumgra(o = pt3, x = 3, y = 1) ## ----------------------------------------------------------------------------- s <- distsummin(pt3) s ## ----------------------------------------------------------------------------- distsum(o = pt3, x = s[1], y = s[2]) distsumgra(o = pt3, x = s[1], y = s[2]) ## ----------------------------------------------------------------------------- plot(pt3) ## ----------------------------------------------------------------------------- contour(pt3) ## ----------------------------------------------------------------------------- contour(pt3, xlim = c(1.9, 2.1), ylim = c(1, 1.2), levels = c(5.465, 5.47, 5.475)) ## ----------------------------------------------------------------------------- persp(pt3) persp(pt3, col = "lightblue", theta = 45, ltheta = 120, shade = 0.75, ticktype = "detailed") ## ----------------------------------------------------------------------------- data(andalusia) o <- loca.p(x = andalusia$x[1: 8], y = andalusia$y[1: 8]) ## ----------------------------------------------------------------------------- xmin <- min(andalusia$x) ymin <- min(andalusia$y) xmax <- max(andalusia$x) ymax <- max(andalusia$y) ## ----------------------------------------------------------------------------- file = system.file('img', 'andalusian_provinces.png', package = 'orloca') img = readPNG(file) plot(o, img = img, main = 'Andalusia', xleft = xmin, ybottom = ymin, xright = xmax, ytop = ymax) ## ----------------------------------------------------------------------------- contour(o, img = img, main = 'Andalusia', xleft = xmin, ybottom = ymin, xright = xmax, ytop = ymax) ## ----------------------------------------------------------------------------- andalusia.loca.p <- loca.p(andalusia$x[1: 8], andalusia$y[1: 8]) sol <- distsummin(andalusia.loca.p) sol ## ----------------------------------------------------------------------------- contour(o, img = img, main = 'Andalusia', xleft = xmin, ybottom = ymin, xright = xmax, ytop = ymax) points(sol[1], sol[2], type = 'p', col = 'red')