ggplot2轴的主题-x和y轴之间的间隙 [英] A theme for axis for ggplot2 - gap between x and y axis

查看:134
本文介绍了ggplot2轴的主题-x和y轴之间的间隙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码生成了一个简单的直方图:

  d< -rnorm(1000,o,1);历史(d) 

我们可以使用 bty =" n" 在基本R绘图命令中创建类似的轴设置.

我的问题: ggplot 中有什么方法可以创建这样的轴设置(轴在原点不相交)?

法罗克

解决方案

ggh4x软件包具有(v1.0.0)创建于2021-04-19 sup>

I used the following code to generate a simple histogram:

d<-rnorm(1000, o, 1);
hist(d)

We can create similar axes setting in the base R plot command by using bty="n".

My question: Is there any way in ggplot to create such an axes setting (the axes are not intersected at the origin)?

Farrokh

解决方案

The ggh4x package has truncated axes (Disclaimer: I wrote the package, so I'm not unbiased). By default, it cuts the axis off at the two most extreme breakpoints, but you can set different options.

library(ggplot2)
library(ggh4x)

set.seed(42)
df <- data.frame(d = rnorm(1000))

ggplot(df, aes(d)) +
  geom_histogram() +
  guides(x = "axis_truncated", y = "axis_truncated") +
  theme(axis.line = element_line())
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

Created on 2021-04-19 by the reprex package (v1.0.0)

这篇关于ggplot2轴的主题-x和y轴之间的间隙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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