ggplot2 0.9.1:带有条形图的对数y轴比例 [英] ggplot2 0.9.1: Logarithmic y-axis scale with barchart

查看:100
本文介绍了ggplot2 0.9.1:带有条形图的对数y轴比例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将条形图的y轴转换为对数刻度(即每个刻度之间的对数距离)。

一些虚拟数据:(data_frame(num = c(1,2,3),label = c(a, b,c))

我试过下面的例子:

  p < -  ggplot(data = DF,aes(x = label,y = num))+ geom_bar()+ 
scale_y_continuous(trans ='log10',
breaks = trans_breaks(log10,function(x)10 ^ x),
labels = trans_format(log10,math_format(10 ^ .x)))

这个日志只转换标签,但不转换:

  p < -  ggplot(data = DF,aes(x = label,y = num))+ geom_bar()+ coord_trans(y =log10)

这根本不绘制任何内容:

  p < -  ggplot(data = DF,aes(x = label,y = num),y =log)

没有任何运气

我h ave也阅读 0.9转换指南,但这似乎并不我也忘了包括一个我试过的例子:

$
$ b

编辑:




$ b $ p

产生以下警告:

警告消息:
在pretty(trans(x),n,...)中:NaNs产生

解决方案

如果你想做一个log 10 scale的使用

  p + scale_y_log10()


I am trying to convert the y-axis of a bar-chart to a logarithmic scale (I.e. logarithmic distance between each ticks).

Some dummy data:

DF <- data.frame(num=c(1,2,3),label=c("a","b","c"))

I've tried the following examples:

p <- ggplot(data=DF,aes(x=label,y=num)) + geom_bar() +
  scale_y_continuous(trans = 'log10',
                     breaks=trans_breaks("log10",function(x) 10^x),
                     labels=trans_format("log10",math_format(10^.x)))

This only log transforms labels, but not ticks:

p <- ggplot(data=DF,aes(x=label,y=num)) + geom_bar() + coord_trans(y="log10")

This doesn't plot anything at all:

p <- ggplot(data=DF,aes(x=label,y=num),y="log")

No luck either

I have also read the 0.9 transition guide , but that does not seem to work either.

EDIT:

I forgot to include one example I tried:

p <- ggplot(data=DF,aes(x=label,y=num)) + geom_bar() + scale_y_log10()

Which produces the following warning:

Warning message: In pretty(trans(x), n, ...) : NaNs produced

解决方案

if you want to do a log 10 scale use

p + scale_y_log10()

这篇关于ggplot2 0.9.1:带有条形图的对数y轴比例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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