用于ggplot中日志缩放的漂亮轴标签 [英] Pretty axis labels for log scale in ggplot

查看:114
本文介绍了用于ggplot中日志缩放的漂亮轴标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试以下任一方法时,轴比例为1e + 03,1e + 06,1e + 09 - 是否有可能获得上好的上标10 ^ 3,10 ^ 6,10 ^ 9而不采用手动标记?

  qplot(1:10,10 ^(1:10))+ scale_y_log10()
qplot(1:10,10 ^(1:10),log ='y')


<您可以使用 trans_breaks() trans_format()从库 scale 获得所需的轴值格式。

  library(scale)
qplot(1:10,10 ^(1:10))+
scale_y_log10(breaks = trans_breaks(log10,function(x)10 ^ x),
labels = trans_format(log10,math_format(10 ^ .x)))


When I try either of the following the axis scale is 1e+03, 1e+06, 1e+09 - is it possible to get nice superscripted 10^3, 10^6, 10^9 instead without resorting to manual labelling? I seem to recall getting this automatically in the past.

qplot(1:10, 10^(1:10))+scale_y_log10()
qplot(1:10, 10^(1:10), log='y')

解决方案

You can use trans_breaks() and trans_format() from library scales to get desired formatting of axis values.

library(scales)
qplot(1:10, 10^(1:10)) +
     scale_y_log10(breaks = trans_breaks("log10", function(x) 10^x),
              labels = trans_format("log10", math_format(10^.x)))

这篇关于用于ggplot中日志缩放的漂亮轴标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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