繁体   English   中英

R & geom_histogram:对数图的条形位置

[英]R & geom_histogram: bar positions for log plots

我正在做一些分析并想插入一个直方图。 我目前的代码是:

g <- ggplot(tg2, aes(x = n))
g <- g + geom_histogram(color = "white", fill = "steelblue", bins = 43)
g <- g + scale_x_continuous(trans = 'log10',
        breaks = trans_breaks('log10', function(x) 10^x),
        labels = trans_format('log10', math_format(10^.x)))
g <- g + scale_y_continuous(trans='log10',
        breaks = trans_breaks('log10', function(x) 10^x),
        labels = trans_format('log10', math_format(10^.x)))
g <- g + annotation_logticks()
g

结果 plot 是: 这个直方图

是否有可能(甚至微不足道)让各个条与水平轴上的对数刻度线对齐? 我已经搜索过,但空无一物。

灰色背景呢? 是否可以让白色网格处于相同的对数刻度上?

几件事。 首先,是什么让你选择bins = 43 其次,是否需要手动提供秤? 如果数据格式正确,则不需要它。 如果不是,请先转换数据,然后再执行。

第三,灰色背景来自默认主题。 几种选择,但我喜欢minimal . linedraw minimal bw有白色网格。

(我为这个例子生成了 1000 个随机数。)

v = tibble(var = rnorm(1000))
ggplot(v, aes(x = var)) +
   geom_histogram(bins = 20) +
   theme_minimal()

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM