J

ggplot2 で対数軸の目盛を変更

まず普通にプロット.

g <- ggplot(data=diamonds)
g <- g + geom_point(aes(carat,price))
print(g)

f:id:joker1110:20110803191408p:image:w360
これを対数軸に変換

g <- g + scale_x_log10()
g <- g + scale_y_log10()
print(g)

f:id:joker1110:20110803191407p:image:w360
目盛がおかしな値になる.そこで,breaksで目盛を付ける位置を,labelsで目盛の表示名をすることができる.

xbreaks <- c(0.5,1,1.5,2,2.5,3)
ybreaks <- seq(5000,20000,5000)
g <- g + scale_x_log10(breaks=xbreaks,labels=xbreaks)
g <- g + scale_y_log10(breaks=ybreaks,labels=ybreaks)
print(g)

f:id:joker1110:20110803191406p:image:w360
さらに,その目盛から軸の表示範囲を指定することもできる.

g <- g + coord_cartesian(xlim=c(0.5,1.5), ylim=c(3000,5000)) 
print(g)

f:id:joker1110:20110803191405p:image:w360
以上,対数軸の設定変更方法でした.