Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
928 views
in Technique[技术] by (71.8m points)

r - Pretty axis labels for log scale in ggplot

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')
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)))

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...