更新:OP 请求见 cmets:
我们可以这样:
ggplot(pop_usa, aes(long,lat)) +
geom_polygon(aes(group = group, fill = estimated_pop_2020 ) ,color="black") +
theme(axis.title.x=element_blank(), axis.text.x=element_blank(),
axis.ticks.x=element_blank(), axis.title.y=element_blank(),
axis.text.y=element_blank(), axis.ticks.y=element_blank(),
plot.title = element_text(face = "bold",hjust = 0.5)) +
ggtitle("Estimated population by state") +
scale_fill_gradient(name ="Estimated population (log10)" ,
low = "#FFFFCC" ,
high = "#336600") +
geom_point(aes(x=long, y=lat)) +
geom_text(label=unique(pop_usa$state),
x=pop_usa$long[10],
y=pop_usa$lat[8]
, size = 3, hjust=0, vjust=-1) +
coord_map()
第一个答案:
按照 cmets 中@Allan Cameron 提供的说明进行操作,然后试试这个:
ggplot(pop_usa, aes(long,lat)) +
geom_polygon(aes(group = group, fill = estimated_pop_2020 ) ,color="black") +
theme(axis.title.x=element_blank(), axis.text.x=element_blank(),
axis.ticks.x=element_blank(), axis.title.y=element_blank(),
axis.text.y=element_blank(), axis.ticks.y=element_blank(),
plot.title = element_text(face = "bold",hjust = 0.5)) +
ggtitle("Estimated population by state") +
scale_fill_gradient(name ="Estimated population (log10)" ,
low = "#FFFFCC" ,
high = "#336600") +
geom_point(aes(x=long, y=lat)) +
geom_text(aes(label = state), size = 3, hjust=0, vjust=-1) +
coord_map()
数据:
df <- structure(list(state = c("alabama", "alabama", "alabama", "alabama",
"alabama", "alabama", "alabama", "alabama", "alabama", "alabama",
"alabama", "alabama", "alabama", "alabama", "alabama", "alabama",
"alabama"), estimated_pop_2020 = c(4.823357, 4.823357, 4.823357,
4.823357, 4.823357, 4.823357, 4.823357, 4.823357, 4.823357, 4.823357,
4.823357, 4.823357, 4.823357, 4.823357, 4.823357, 4.823357, 4.823357
), long = c(-87.46201, -87.48493, -87.52503, -87.53076, -87.57087,
-87.58806, -87.59379, -87.59379, -87.674, -87.81152, -87.88026,
-87.92037, -87.95475, -88.00632, -88.01778, -88.01205, -87.99486
), lat = c(30.38968, 30.37249, 30.37249, 30.33239, 30.32665,
30.32665, 30.30947, 30.28655, 30.27509, 30.2579, 30.24644, 30.24644,
30.24644, 30.24071, 30.25217, 30.26936, 30.27509), group = c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L
), order = 1:17), class = "data.frame", row.names = c("1", "2",
"3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14",
"15", "16", "17"))