【发布时间】:2023-03-21 14:14:01
【问题描述】:
我正在尝试将图例标题移动到 ggmap 中的颜色栏(用于在 R 中使用 ggplot2 绘制地图的包)。我有两个问题:
-
如何让图例标题位于颜色栏的顶部(而不是左侧,如下所示)?
-
有没有办法让颜色条变长?
这是我的代码:
CenterOfMap <- geocode("41.396108,2.059348")
Ciutat_Map <- get_googlemap(c(lon=CenterOfMap$lon, lat=CenterOfMap$lat),
zoom = 11, maptype = "terrain", source = "google", color="bw",
style=c(feature="all", element="labels",visibility="off"))
Ciutat_Map <- ggmap(Ciutat_Map, extent = "device")
Ciutat_Map <- Ciutat_Map +
geom_polygon(aes(x=long, y=lat, fill=TOTAL, group=group),
data=Hex_Grid_Pop_data, alpha =0.7)
Ciutat_Map <- Ciutat_Map +
scale_fill_gradientn(colours = c("#e5d5f2", "#cdb4db", "#b293c2", "#9d78ad",
"#855a96", "#724485", "#5d2c70"),
limits=c(0, 1700), oob=squish, space = "Lab",
na.value = "transparent", guide = "colourbar")
Ciutat_Map <- Ciutat_Map +
theme(legend.position = c(0.90,0.1),
legend.direction = "horizontal",
legend.title = element_text(size = 16),
legend.text = element_text(size = 14)) +
labs(fill = "Total Population")
Ciutat_Map
【问题讨论】: