Closed trinker closed 10 years ago
Read in the image:
ggplot(data.frame(x=c(0, 1), y=c(0, 1))) + theme_bw()+ geom_point(aes(x=x, y=y)) +
annotation_custom(rasterGrob(readPNG("being.png"),0,0,1,1,just=c("left","bottom")),0,1,0,1) +
scale_x_continuous(breaks=seq(0, 1, .05)) +
scale_y_continuous(breaks=seq(0, 1, .05)) +
theme(axis.text.x=element_text(angle=-90))
library(qdap)
dat <- list(
`01`=data.frame(x=c(.4, .4, .6, .6), y=c(.67, .525, .525, .67)),
`02`=data.frame(x=c(.35, .4, .6, .65), y=c(.75, .67, .67, .75)),
`03`=data.frame(x=c(.6, .65, .65, .6), y=c(.525, .475, .75, .67)),
`04`=data.frame(x=c(.4, .35, .65, .6), y=c(.525, .475, .475, .525)),
`05`=data.frame(x=c(.35, .35, .4, .4), y=c(.75, .475, .525, .67)),
`06`=data.frame(x=c(.4, .4, .6, .6), y=c(.87, .75, .75, .87)),
`07`=data.frame(x=c(.6, .6, .65, .65, .73, .73), y=c(.87, .75, .75, .67, .67, .87)),
`08`=data.frame(x=c(.65, .65, .73, .73), y=c(.67, .525, .525, .67)),
`09`=data.frame(x=c(.6, .6, .73, .73, .65, .65), y=c(.475, .28, .28, .525, .525, .475)),
`10`=data.frame(x=c(.4, .4, .6, .6), y=c(.475, .28, .28, .475)),
`11`=data.frame(x=c(.27, .27, .4, .4, .35, .35), y=c(.525, .28, .28, .475, .475, .525)),
`12`=data.frame(x=c(.27, .27, .35, .35), y=c(.67, .525, .525, .67)),
`13`=data.frame(x=c(.27, .27, .35, .35, .4, .4), y=c(.87, .67, .67, .75, .75, .87)),
`14`=data.frame(x=c(.35, .35, .65, .65), y=c(1, .87, .87, 1)),
`15`=data.frame(x=c(.65, .65, .73, .73, 1, 1), y=c(1, .87, .87, .75, .75, 1)),
`16`=data.frame(x=c(.73, .73, 1, 1), y=c(.75, .475, .475, .75)),
`17`=data.frame(x=c(.65, .65, 1, 1, .73, .73), y=c(.28, 0, 0, .475, .475, .28)),
`18`=data.frame(x=c(.35, .35, .65, .65), y=c(.28, 0, 0, .28)),
`19`=data.frame(x=c(0, 0, .35, .35, .27, .27), y=c(.475, 0, 0, .28, .28, .475)),
`20`=data.frame(x=c(0, 0, .27, .27), y=c(.75, .475, .475, .75)),
`21`=data.frame(x=c(0, 0, .27, .27, .35, .35), y=c(1, .75, .75, .87, .87, 1))
)
dat <- lapply(dat, function(x) {
x$order <- 1:nrow(x)
x
})
space.manikin.shape <- list_df2df(dat, "id")[, c(2, 3, 1, 4)]
## add order
centers <- data.frame(
id = unique(space.manikin.shape$id),
center.x=c(.5, .5, .625, .5, .375, .5, .66, .69, .66, .5, .34, .31,
.34, .5, .79, .815, .79, .5, .16, .135, .16),
center.y=c(.597, .71, .5975, .5, .5975, .82, .81, .5975, .39, .3775, .39,
.5975, .81, .935, .89, .6025, .19, .14, .19, .6025, .89)
)
merge(space.manikin.shape, centers)[, c(2:3, 1, 4:6)]
library(png)
img[["raster"]][128, 128]
img <- rasterGrob(readPNG("being.png"),0,0,1,1,just=c("left","bottom"))
img[["raster"]][img[["raster"]] == "#0E0F0FFF"] <- "#E7E7E7"
ggplot(centers) + annotation_custom(img,0,1,0,1) +
geom_map(aes(map_id = id), map = space.manikin.shape, colour="black", fill=NA) +
theme_bw()+
expand_limits(space.manikin.shape) +
geom_text(data=centers, aes(center.x, center.y, label = id), color="grey60")
I decided against this as a function. I made this into a blog post instead: http://trinkerrstuff.wordpress.com/2014/04/12/shape-file-selfies-in-ggplot2/
McNeil has a space manikin. So create a shape file to make the manikin called
space.manikin.shape
. Then a functionspace_manikin
to take people's data and make either a choropleth or a density map.p. 275 McNeil (2005) example
shape file would take the form of: