データサイエンティスト上がりのDX参謀・起業家

データサイエンティスト上がりのDX参謀・起業家のブログ。データ分析や事業について。自身はアーティスト、経営者、事業家。

ggplot2での軸の変更

isseing3332010-07-06


ggplot2のscale_continuousオプションでいろいろ軸(axis)をいじれるようです。

  • y軸に3桁ずつコンマを入れる、x軸は%表記にする


  • y軸を自然対数に、x軸を逆にする


プログラムはこちら↓

#axis of ggplot2
library(ggplot2)
(m <- qplot(rating, votes, data=subset(movies, votes > 1000), na.rm = T)) 
m + scale_y_continuous(formatter = "comma") + scale_x_continuous(formatter = "percent")
m + scale_y_log10() + scale_x_reverse()
m + scale_y_continuous(formatter = "dollar")