首页 > 解决方案 > ggplot中的相同比例

问题描述

我想要两个尺度都等于范围,如何在 ggplot2 中做到这一点:

ggplot2 可重现的例子

mtcars %>% ggplot(aes(x = wt, y = drat)) + geom_point()

标签: rggplot2

解决方案


这是一个例子:

library(tidyverse)
library(wrapr)

mtcars %.>%
  ggplot(., aes(x = wt, y = drat)) +
  geom_point() +
  coord_cartesian(
    xlim = c(min(pmin(.$wt, .$drat)), max(pmax(.$wt, .$drat))) -> sc_range,
    ylim = sc_range
  )

推荐阅读