Search code examples
rggplot2ggmapcaption

Plotting ggmap coming out too small in viewer/html


enter image description hereI have plotted a sailing yachts race on top of a google map, however when I render it into a html it comes out small and roughly 40mm x 40mm on my screen. I want it to be a full screen/page if possible or have control over the sizing.

Here is the code the produces the map I want but not the size I want!

logdata=read.csv(file=file.choose(), header=T , sep=",",na.strings="'",stringsAsFactors=F)
lg = logdata


library(plotKML)
library(ggplot2)
library(ggmap)
library(gganimate)
register_google("api")

map_theme <- list(theme(legend.position = "bottom",
                        panel.grid.minor = element_blank(),
                        panel.grid.major = element_blank(),
                        panel.background = element_blank(),
                        plot.background = element_rect(fill = "white"),
                        panel.border = element_blank(),
                        axis.line = element_blank(),
                        axis.text.x = element_blank(),
                        axis.text.y = element_blank(),
                        axis.ticks = element_blank(),
                        axis.title.x = element_blank(),
                        axis.title.y = element_blank(),
                        plot.caption = element_text(),
                        plot.title = element_text(size = 18)))

avTws = mean(lg$TWS, na.rm = T, trim = 0.5)
Lon = mean(lg$Lon, na.rm = T)
Lat = mean(lg$Lat, na.rm = T)
maxlon = max(lg$Lon, na.rm = T)
maxlat = max(lg$Lat, na.rm = T)
minlon = min(lg$Lon, na.rm = T)
minlat = min(lg$Lat, na.rm = T)


lg$Time =as.POSIXct(lg$Time, format = "%H:%M:%OS")


mapImageData <- get_googlemap(center = c(lon = Lon, lat = Lat),
                              zoom = 12,
                              color = "color",
                              scale = 4,
                              maptype = c("terrain"))
race1 = ggmap(mapImageData, extent = "panel") +
  geom_line(data = lg, mapping = aes(x = lg$Lon, y = lg$Lat, color = lg$SOG), size = 1)+
  scale_x_continuous(limits = c(minlon, maxlon), expand = c(0.018, 0.018))+
  scale_y_continuous(limits = c(minlat, maxlat), expand = c(0.018, 0.018))+
  scale_colour_gradientn(colours=rainbow(5))+
  transition_reveal(lg$Time)+
  labs(title = "Race 1",
       subtitle = "TWS")+
  map_theme

race1
animate(race1, fps = 10, duration = 60)

Solution

  • I managed to change the size of the map by using

    options(gganimate.dev_args = list(width = 1000, height = 1000))

    Which will change all default gganimate arguments but you can change this by giving arguments directly to animate()