Я использую здесь пример для обсуждения: карта ggplot с l
library(rgdal)
library(ggplot2)
library(maptools)
# Data from http://thematicmapping.org/downloads/world_borders.php.
# Direct link: http://thematicmapping.org/downloads/TM_WORLD_BORDERS_SIMPL-0.3.zip
# Unpack and put the files in a dir 'data'
gpclibPermit()
world.map <- readOGR(dsn="data", layer="TM_WORLD_BORDERS_SIMPL-0.3")
world.ggmap <- fortify(world.map, region = "NAME")
n <- length(unique(world.ggmap$id))
df <- data.frame(id = unique(world.ggmap$id),
growth = 4*runif(n),
category = factor(sample(1:5, n, replace=T)))
## noise
df[c(sample(1:100,40)),c("growth", "category")] <- NA
ggplot(df, aes(map_id = id)) +
geom_map(aes(fill = growth, color = category), map =world.ggmap) +
expand_limits(x = world.ggmap$long, y = world.ggmap$lat) +
scale_fill_gradient(low = "red", high = "blue", guide = "colorbar")
Дает следующие результаты:
Я хотел бы отобразить одну переменную в левую "половину" страны и другую переменную в правую "половину" страны. Я поставил "половину" в кавычки, потому что он не был четко определен (или, по крайней мере, я не четко определяю его). Ответ Ian Fellows может помочь (что дает простой способ получить центроид). Я надеюсь на что-то, чтобы я мог сделать aes(left_half_color = growth, right_half_color = category)
в этом примере. Меня также интересуют верхняя половина и нижняя половина, если это другое.
Если возможно, я также хотел бы сопоставить отдельные центроиды половинок с чем-то.