ggplot2 で対数軸の目盛を変更
まず普通にプロット.
g <- ggplot(data=diamonds) g <- g + geom_point(aes(carat,price)) print(g)
g <- g + scale_x_log10() g <- g + scale_y_log10() print(g)
目盛がおかしな値になる.そこで,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)
g <- g + coord_cartesian(xlim=c(0.5,1.5), ylim=c(3000,5000)) print(g)