在ggplot2中翻转并保持图表的纵横比 [英] Flipping and maintaining aspect ratio of a chart in ggplot2

查看:296
本文介绍了在ggplot2中翻转并保持图表的纵横比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个水平直方图,并使用 ggplot2 调整图表纵横比。

例如,

假设我的图表是 dia < - ggplot(diamonds,aes(x = color))+ geom_bar()



我可以使用 dia + coord_flip()将其翻转为水平。我也可以调整长宽比例如 dia + coord_fixed(ratio = .001)



但是,当我将 dia + coord_flip()+ coord_fixed(ratio = .001),图表不再水平。



有什么方法可以实现我要使用 ggplot2

解决方案

在ggplot2邮件列表中查看此答案


您只能在给定的ggplot上使用一个coord _ *()函数,因为
会在完成其他所有操作后更改坐标系。至
改变宽高比,您可以在
主题系统中使用相应的参数:



  + coord_flip()+ theme(aspect.ratio = 1)


I want to create a horizontal histogram, and adjust the chart aspect ratio using ggplot2 .

For example let's say my chart is dia <- ggplot(diamonds, aes(x=color)) + geom_bar().

I can flip this to be horizontal using dia + coord_flip().

I can also adjust the aspect ratio e.g. dia + coord_fixed(ratio=.001).

But when I combine them dia + coord_flip()+ coord_fixed(ratio=.001), the chart is no longer horizontal.

Is there any way to achieve what I want using ggplot2?

解决方案

See this answer on the ggplot2 mailing list :

You can only use one coord_*() function on a given ggplot since it changes the coordinate system after everything else has been done. To change the aspect ratio, you can use the corresponding argument in the theming system:

 + coord_flip() + theme(aspect.ratio = 1)

这篇关于在ggplot2中翻转并保持图表的纵横比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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