LoginSignup
1
1

More than 3 years have passed since last update.

Rのggplot2で散布図のポイントの大きさの区切りを変更したい場合

Last updated at Posted at 2019-09-27

探すと意外とこの操作を書いているブログ記事がなかったので、備忘録を含めて投稿しておきます。
よくこのサイトに助けられている、仕事でRを使うユーザーです。

ggplot2 パッケージのgeom_pointで散布図を描きたい場合、点の大きさを何らかの連続的な変数(例えば人口やGDP)で表す場合があると思います。これ自体は、

plot.r
g01 <- ggplot(何かのdf,aes(x = 横軸変数,y = 縦軸変数)) +
       geom_point(aes(size = 人口))
plot(g01)

で表示されますが、たまに、人口による点の大きさがソフトのほうで任意で設定されるので、こっちの思い通りの図にならない場合があると思います。
そういう場合は、

plot2.r
g01 <- ggplot(何かのdf,aes(x = 横軸変数,y = 縦軸変数)) +
       geom_point(aes(size = 人口))+
       scale_size(name="凡例名",
       breaks = c(100,1000,10000,10000000))
plot(g01)

とこのscale_size関数のbreaksのところで連続数の区切りを任意に変更できますので、同じ悩みを持つ人はご参考までに。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1