LoginSignup
1
2

More than 5 years have passed since last update.

xyplotでカテゴリ描いた図の順番を逆にしたい

Posted at

Rのlatticeパッケージのxyplotでカテゴリごと描いた図の順番を逆にしたい。
組み込みデータのairqualityを使って説明してみる。
月ごとに,温度とオゾンの散布図を描く。

library("lattice")
xyplot(Ozone ~ Temp | Month,
layout=c(1,5),
data=airquality
)

f1.jpg

この図だと,月ごとのグラフが下から上と並ぶのが気持ち悪いので,逆順にしたい。
当たり前だけど,y軸の最大値と最小値を逆にしてylimで設定したのではうまくいかない。
オプションのas.tableを使う。

xyplot(Ozone ~ Temp | Month,
layout=c(1,5),
data=airquality,
as.table=T
)

f2.jpg
逆順に並びました。
丁寧にやるなら,本当はMonthをfactorにして,levelを指定すれば良い。

月名を表示させた例は次回に。

1
2
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
2