ggtitle没有用ggmap显示

时间:2018-03-11 12:10:39

标签: r ggmap

我不明白为什么ggtitle(" My Title")+或labs(title =" My Title")+没有显示我的标题。这是我的代码:

require(raster)
country <- getData("GADM", country="Australia",level = 0)

points <- data.frame(id = c(1:5), lon = c(125, 144, 150, 115, 139), lat = c(-20, -15, -34, -25, -21))
edges <- data.frame(from.lon = c(144, 139, 125), from.lat = c(-15,-21, -20), to.lon = c(150, 125, 144), to.lat = c(-34, -20, -15), resource_id = c(1:3))

centrepoint <- as.numeric(geocode("Australia"))


p1 <- ggmap(get_googlemap(center = centrepoint, scale = 2, zoom = 4,    maptype = "satellite"), extent = "device") +
  geom_polygon(data = country, aes( x = long, y = lat, group = group),  fill = NA, color = "white", size = 0.25) +
  geom_segment(data = filter(edges, edgelist$resource_id == 2),
               size = 0.5,
               color = "pink",
               aes(y = from.lat, x = from.lon, yend =  to.lat, xend = to.lon),
           arrow = arrow(length = unit(0.25, "cm"), type = "closed")) +
  coord_fixed(1.3) +
  geom_point(aes(x = lon, y = lat), data = points, col = "pink", alpha = 0.5, size = 1.0) +
  ggtitle("Money") +
  theme(plot.margin = unit(c(1,1,1,1), "cm"))
p1

我还在学习ggplot。

1 个答案:

答案 0 :(得分:1)

如果没有至少可重复的数据,那么回答这个问题有点困难。如果没有这些信息,您的geom来电之一(我的猜测是geom_polygon())或相关数据似乎存在问题,因为这样可以正常工作:

library(ggplot2)
library(ggmap)

ggmap(
  get_googlemap(
    scale = 2, 
    zoom = 7, 
    maptype = "satellite"
    ), 
  extent = "device") +
  coord_fixed(1) +
  labs(title = "Money") + 
  # ggtitle("Money)
  theme(plot.margin = unit(c(1,1,1,1), "cm"))