我想知道这是否对ggplot要求太多。我正在尝试使用 facet_grid 在与它们相关的地理区域上绘制一些图表结果似乎在正轨上,但是在正确缩放比例以及摆脱未使用的网格框时存在一些问题。我想知道是否有人知道如何调整它以使其工作?
该示例基于内置的美国州数据集。
任何帮助表示赞赏!
# My failed attempt to regional summary graphs plotted over the region centroid (to overlay onto map):
# example based on the States dataset
require(ggplot2)
# Approx centroid coordinates for the US regions - I created these as the information is missing from the dataset
lat <- c(32L, 42L, 42L, 32L, 42L, 42L, 43L, 32L, 32L, 32L, 42L, 42L, 43L, 43L, 43L, 43L, 32L, 32L, 43L, 32L, 43L, 43L, 43L, 32L, 43L, 42L, 43L, 42L, 43L, 43L, 42L, 43L, 32L, 43L, 43L, 32L, 42L, 43L, 43L, 32L, 43L, 32L, 32L, 42L, 43L, 32L, 42L, 32L, 43L, 42L)
lon <- c(-88L, -114L, -114L, -88L, -114L, -114L, -73L, -88L, -88L, -88L, -114L, -114L, -91L, -91L, -91L, -91L, -88L, -88L, -73L, -88L, -73L, -91L, -91L, -88L, -91L, -114L, -91L, -114L, -73L, -73L, -114L, -73L, -88L, -91L, -91L, -88L, -114L, -73L, -73L, -88L, -91L, -88L, -88L, -114L, -73L, -88L, -114L, -88L, -91L, -114L)
region.centres <- data.frame(lon = lon, lat = lat)
state.x77 <- data.frame(state.x77)
state.x77$State <- row.names(state.x77)
region <- data.frame(Region = as.character(state.region))
data <- data.frame(c(data.frame(state.x77), region, region.centres))
# I can plot a random summary graph for each region:
p <- ggplot(data, aes(Income, colour = 'red')) +
geom_density(alpha = 0.2)
# But trying to plot onto centroid nearly works but results in loss of geographical positional accuracy
# and includes various graphs that fill the empty grid slots but are not necessary
p + facet_grid(lat ~ lon, space = "free", drop=T)
# How can I get uniform discrete graphs to sit over the centroid for each region?