ggplot2の軸を上付きのべき乗で書きたい
そういうことです。
今のところの私の答えは以下で
- breaksでちゃんとX軸のどれを書くかを指定
- trans_formatでべき乗表示に変換
です。
ggplot(data=data.frame(x=10^(1:4), y=1:4), aes(x=x, y=y)) + scale_x_log10(breaks=10^(1:4), labels=trans_format('log10',math_format(10^.x)))+geom_point()
以下、途中の試行錯誤
breaks指定なし+横軸LOGにしない場合
横軸の値があまりにいけてないマンになる。
ggplot(data=data.frame(x=10^(1:4), y=1:4), aes(x=x, y=y)) + scale_x_continuous(labels=trans_format('log10',math_format(10^.x)))+geom_point()
横軸をlog10にしない場合
さすがに見辛い
ggplot(data=data.frame(x=10^(1:4), y=1:4), aes(x=x, y=y)) + scale_x_continuous(breaks=10^(1:4), labels=trans_format('log10',math_format(10^.x)))+geom_point()
fancy_scientificをパクる場合
を参考にマルっとfancy_scientific関数をもらってきてからのPLOT。
breaksを陽に指定できない場合はこれでよい気もする。
fancy_scientific <- function(l) { # turn in to character string in scientific notation l <- format(l, scientific = TRUE) # quote the part before the exponent to keep all the digits l <- gsub("^(.*)e", "'\\1'e", l) # turn the 'e+' into plotmath format l <- gsub("e", "%*%10^", l) # return this as an expression parse(text=l) } ggplot(data=data.frame(x=10^(1:4), y=1:4), aes(x=x, y=y)) + scale_x_continuous(labels=(labels=fancy_scientific))