##### install stuff and set stuff #####
require(maps)
require(rgl)
require(maptools)
require(rgdal)
require(tidyverse)
#setwd('C:/Users/didac/Downloads/mygeodata')
### Ids corresponding to parcelations in this image
GeoAparc = cbind(
id = c(0, 1, 4,7, 8,9,15,17,20,21,22,23,28,32,34,39,41,49),
area = c("parstriangularis","smn","motor","ipl","stg","mtg","loc","rmf",
"lvmpfc","bankssts","insula","spc","itg","visual","cmf","parsorbitalis",
"supfrontal","transverse")
) %>% as.data.frame(stringsAsFactors=F)
##### main routine #####
#Open geo object (shape file)
geobrain <- readOGR(dsn = ".", layer = "thethird")
#transform to data.frame
geobrain <- fortify(geobrain, region="GEO_ID")
head(geobrain)
## RAW PLOT commentary:
# as the raw plot is far from perfect there are several polygons that do not correspond
# to any aparc. Yet due to the way the image is transformed most of the lower indices should correspond
# to real regions
#### some cleaning can be done #####
# to remove unlikely polygons: geobrain2 <- geobrain[as.numeric(geobrain$id) < 50,]
# to check individual regions: geobrain2 <- geobrain[as.numeric(geobrain$id) == 12]
# to retain more complex polygons: sort(table(as.numeric(geobrain$id)))
# here the following combination worked well - though some manual labour
geobrain2 <- geobrain[as.numeric(geobrain$id) < 50,]
sort(table(as.numeric(geobrain$id)))
geobrain2 <- geobrain %>% filter(id %in% GeoAparc$id & id < 50)
ggplot(data = geobrain2) +
geom_polygon(aes(x = long, y = lat, group = as.factor(id), fill=as.numeric(id)), color = "white", size = .5) +
coord_fixed() + theme_classic() +
theme(legend.position = "none")
# plot
ggplot(data = geobrain2) +
geom_polygon(aes(x = long, y = lat, group = as.factor(id), fill=as.numeric(id)),
color = "white", size = .5) +
coord_fixed() +
theme_classic() +
theme(legend.position = "none")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.