具有自由刻度的刻面,但保持长宽比固定 [英] Facet with free scales but keep aspect ratio fixed

查看:85
本文介绍了具有自由刻度的刻面,但保持长宽比固定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ggplot绘制多面地图,并且一直无法解决如何在保持xy长宽比固定的同时允许每个小面自由"缩放(以使小区域看起来不会太小)的问题.

I am using ggplot to draw faceted maps and have been unable to work out how to allow "free" scales in each facet (so that small regions don't look too small) while keeping the x-y aspect ratio fixed.

这是一个简化的示例:

require(maps)
require(ggplot2)

map_nz <- subset(fortify(map_data('nz')),
                 region %in% c("South.Island ", "North.Island "))
gg_nz <- qplot(long, lat, data=map_nz, geom="polygon", group=group)

我现在有一个新西兰北岛和南岛的地块.我可以对此进行说明,并以固定的长宽比显示它,如下所示:

I now have a plot of the North and South Islands of New Zealand. I can facet this and display it with a fixed aspect ratio like this:

gg_nz + coord_fixed() + facet_wrap(~region)

结果如下:

请注意,北岛方面有很多空间被浪费了.我希望它占用更多的可用空间.我可以这样释放秤:

Notice that there is quite a bit of space wasted in the North Island facet. I would like it to take up more of the available space. I can free up the scales like this:

gg_nz + facet_wrap(~region, scales="free")

具有以下结果:

问题在于每个小平面的x-y长宽比不再是1:1.我很高兴每个方面都有不同的比例,但是我希望在方面内保持宽高比.

The problem is that the x-y aspect ratio is no longer 1:1 in each facet. I am happy to have each facet on a different scale, but within the facet I would like to preserve the aspect ratio.

我尝试了以下操作但未成功:

I tried the following without success:

gg_nz + facet_wrap(~region, scales="free") + coord_fixed()

大概facet_wrap中的scale参数将覆盖coord_fixed.有什么建议吗?

Presumably the scale parameter in facet_wrap overrides coord_fixed. Any suggestions?

更新:为了提供更生动的说明,这与美国某些州的现象相同:

UPDATE: to give a more dramatic illustration, here is the same phenomenon with some US states:

固定坐标(使用coord_fixedcoord_equal):

自由坐标(使用scales = free):

Free coords (using scales = free):

这些地图都不是理想的:首先,特拉华州很小.在第二个方面,纵横比是相当失真的.例如,处于狭窄状态的新泽西州被拉得太宽.

Neither of these maps is ideal: in the first, Delaware is tiny. In the second, the aspect ratios are quite distorted. New Jersey, which is a narrow state, is stretched too wide, for example.

推荐答案

theme(aspect.ratio = 1)可行.

gg_nz + facet_wrap(~region, scales="free") + theme(aspect.ratio = 1)

这篇关于具有自由刻度的刻面,但保持长宽比固定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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