0

我正在创建一系列与不同地区相关的小折线图,然后将其保存为 grobs 并绘制到欧洲地图上。我可以将其保存为 png 文件,然后可以仅使用标准 Windows 照片缩放放大保存的图像上的部分。但是这很慢,缩放的图像需要很长时间才能加载。我想知道是否有更好的方法来做到这一点并尝试使用 svgPanZoom 但我无法获得正确的比例以便它们可见,而不是你可以看到轴而不是图形本身,我也不能弄清楚如何保存绘图,以便仍然可以进行平移和缩放。

有谁知道更好的方法来做到这一点?我的代码在下面,但数据集太大而无法发布示例。

  ###species_preds is a list of model prediction dataframes for different 100km squares in Europe 
  ##so dt is a dataframe with a column for julian day, one for prediction and one each for the upper and lower confidence intervals
 
  ##list_100km_sp is a dataframe of the  x and y centroid locations of all the 100km squares we have prediction 
  data for
 
  ##Europe is a base map, just a filled polygon of Europe 

  list_plots<-list()
  
  
  for (g in 1:length(species_preds)){
    dt<-species_preds[[g]]
    #qualify what's plotted by sample size?
    p<-ggplot(data=dt)+
      geom_line(aes(x=date, y=round(pred,3), group=1),linetype="solid", size=0.05)+
      geom_line(aes(x=date, y=round(u.pred,3), group=1),linetype="dashed", size=0.05)+
      geom_line(aes(x=date, y=round(l.pred,3), group=1),linetype="dashed", size=0.05)+
      xlab("Julian_date")+ylab("Prob of occurrence")+
      theme(legend.position = "none",panel.background = element_blank(), panel.border = element_blank(),
            panel.grid.major = element_blank(), panel.grid.minor = element_blank(), 
            plot.background = element_blank(),axis.line = element_line(colour = "black", size=0.05),
            axis.ticks=element_line(size=0.05),
            text = element_text(size=1), axis.text.x = element_text(angle=90, hjust=1))
    
    list_plots[[g]]<-ggplotGrob(p)
  }
  
  ##plot all on a map
   plot <- Europe + annotation_custom(grob=list_plots[[1]], xmin=list_100km_sp$centroid_x_rounded[1], xmax=list_100km_sp$centroid_x_rounded[1]+130000, ymin=list_100km_sp$centroid_y_rounded[1], ymax=list_100km_sp$centroid_y_rounded[1]+130000)
  for (i in 2:length(list_plots)){
    plot <- plot + annotation_custom(grob=list_plots[[i]], xmin=list_100km_sp$centroid_x_rounded[i], xmax=list_100km_sp$centroid_x_rounded[i]+130000, ymin=list_100km_sp$centroid_y_rounded[i], ymax=list_100km_sp$centroid_y_rounded[i]+130000)
  }
  
  
  ggsave(plot, file="species.png"), dpi=600, height = 90, width =80, units="cm", pointsize=6)

完整地图 放大地图部分

4

0 回答 0