ggplot2 y轴坐标不在日志范围内显示 [英] ggplot2 y-axis ticks not showing up on a log scale

查看:593
本文介绍了ggplot2 y轴坐标不在日志范围内显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用ggplot2来创建boxplot图表,但我无法在ggplot2 webiste的示例中显示标记。





  apples<  -  data.frame(fruit = c(rep(苹果,30)),味道= runif(30,30,50)
banana < - data.frame(fruit = c(rep(banana,30)),taste = runif(30,300 ,500))
orange < - data.frame(fruit = c(rep(orange,30)),taste = runif(30,3000,5000))
fruits <-rbind (苹果,香蕉,橘子)

如果我绘制在,您可以通过以下方式获得相同的效果:
$ b

  library(ggplot2)
library(scales)
ggplot(fruits,aes(fruit,taste) )+
geom_boxplot()+
scale_y_log10(breaks = trans_breaks('log10',function(x)10 ^ x),
labels = trans_format('log10',math_format(10 ^ x)))


I am trying to use ggplot2 to create a boxplot graph but I am having trouble getting the ticks to show up as it does in the examples of the ggplot2 webiste.

Here is some fake data of tastiness of fruits:

apples <- data.frame(fruit=c(rep("apple", 30)), taste=runif(30, 30, 50)
banana <- data.frame(fruit=c(rep("banana", 30)), taste=runif(30, 300, 500))
orange <- data.frame(fruit=c(rep("orange", 30)), taste=runif(30, 3000, 5000))
fruits <- rbind(apples,banana,orange)

If I plot as in the ggplot2 website example the y-axis scale should looks something like:

Instead I get an axis like:

ggplot(fruits, aes(fruit, taste) ) +  geom_boxplot() + scale_y_log10()

How would I get the y-axis scale on scientific notation?

解决方案

I'm assuming that you are using the new 0.9.0 version of ggplot2, which underwent a large amount of changes. This happens to be one of them, I believe.

If I recall correctly, enough people complained about the exponential format being the default, that this was changed. As per the transition guide you can achieve the same effect via:

library(ggplot2)
library(scales)
ggplot(fruits, aes(fruit, taste) ) +  
    geom_boxplot() + 
    scale_y_log10(breaks = trans_breaks('log10', function(x) 10^x),
                  labels = trans_format('log10', math_format(10^.x)))

这篇关于ggplot2 y轴坐标不在日志范围内显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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