ggplot2。翻转坐标轴并保持数据的纵横比

您所在的位置:网站首页 ggplot和ggplot2是一样的吗 ggplot2。翻转坐标轴并保持数据的纵横比

ggplot2。翻转坐标轴并保持数据的纵横比

2023-04-15 17:25| 来源: 网络整理| 查看: 265

百度翻译此文   有道翻译此文 问题描述

In ggplot2, the coord_fixed() coordinate system ensures that the aspect ratio of the data is maintained at a given value. So, the shape of the panel changes to maintain the shape of the data. Meanwhile coord_flip() swaps the axes of the plot. However, a plot in ggplot2 must have exactly one coordinate system, so these functions cannot be combined.

My question is:

Does there exist a way to combine the behaviours of coord_fixed() and coord_flip(), resulting in a coordinate system with the x and y axes exchanged and a fixed aspect ratio of the data?

This is a popular question, however the common answer is incorrect:

How do I to fix aspect ratio and apply coord_flip in ggplot2? Flipping and maintaining aspect ratio of a chart in ggplot2

The commonly suggested answer is to use coord_flip() together with theme(aspect.ratio = 1) instead of coord_fixed(). However, as per the ggplot2 documentation, this setting refers to the "aspect ratio of the panel." Thus, the data will change shape to maintain the shape of the panel.

I suspect that this is a feature that does not currently exist in ggplot2. But more importantly I think that a correct solution or at least response to this question should be documented.

Quick minimal example of the issue:

library(ggplot2) x


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3