-1

I do not understand why ggtitle("My Title") + or labs(title = "My Title") + is not displaying my title. Here is my code:

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

I am still learning ggplot.

aterhorst
  • 625
  • 4
  • 14

1 Answers1

1

It is a bit difficult to answer this question without at least minimal reproducible data. Without that information, it seems as though there is a problem with one of your geom calls (my guess is geom_polygon()) or associated data since this works fine:

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"))