如何减少世界地图的空白边距 [英] How to reduce white space margins of world map

查看:176
本文介绍了如何减少世界地图的空白边距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

library(maptools)
data(wrld_simpl)
plot(wrld_simpl)
box()

这给了我一张世界地图,并显示了地图顶部和底部的大量空白.我希望这个空间消失,因为我需要打印许多(〜60张)地图.我正在将knitr用于将要嵌入地图的报告.例如

This gives me a world map and shows the plentiful white space top and bottom of the map. I would like this space to be gone as I need to print many (~60) maps. I am using knitr for the report in which the maps will be embedded. E.g.

Here is some text.
<<chunk.maps, eval = TRUE>>=
library(maptools)
plot(wrld_simpl)
box()
@
And some more text.

但是我不认为这是一个knitr问题.所以:

But I don't think this is a knitr question. So:

  1. 如何摆脱空白?
  2. 如何确保地图从左到右填充我的页面?

我尝试过maimarpar,但是没有这种运气!我猜为out.width的块选项将给出我的问题2的结果,但是由于我对问题1的关注如此之深,所以我很难说清楚.

I have tried mai, mar, par, but no such luck! I am guessing out.width for the chunk option will give the result for my question 2, but since I am so badly stuck on question 1 I find it hard to tell.

非常感谢!这里有很多东西要学习!

Thank you very much! There is so much to learn out here!

推荐答案

我将ggplot2用于这些类型的地图:

I use ggplot2 for these kinds of maps:

require(ggplot2); theme_set(theme_bw())
wrld_simpl_df = fortify(wrld_simpl)
ggplot(wrld_simpl_df, aes(x = long, y = lat, group = group)) + 
   geom_path() + coord_equal()

这还包括您抱怨的空白.问题在于,x轴和y轴之间的纵横比是固定的.因此,如果您选择方形图形设备,则在其上方和下方将保留白色边框.解决方案是使图形设备与绘图的比例大致相同.使用fig.widthfig.height来执行此操作.有关更多信息,请参见此链接.作为说明,以正确的比例保存上面的图时:

This also includes the whitespace you where complaining about. The problem is that the aspect ratio between the x- and y-axis is fixed. So if you choose a square graphics device, that will leave white borders above and below. The solution is to make your graphics device have roughly the same proportions as your plot. Use fig.width and fig.height to do this. See this link for more info. As an illustration, when saving the plot above with the correct proportions:

ggsave("/tmp/plt.png", width = 16, height = 9)

问题不再存在.

这篇关于如何减少世界地图的空白边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆