在 viewer/html 中绘制的 ggmap 太小了

Plotting ggmap coming out too small in viewer/html

我在 google 地图上绘制了一场帆船比赛,但是当我将它渲染成 html 时,它看起来很小,大约 40mm x 40mm我的屏幕。如果可能的话,我希望它是一个完整的 screen/page 或者可以控制大小。

这是生成我想要的地图但不是我想要的尺寸的代码!

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)

我使用

设法改变了地图的大小

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

这将更改所有默认的 gganimate 参数,但您可以通过直接向 animate() 提供参数来更改它