LoginSignup
1
1

More than 5 years have passed since last update.

R: ggplot2 使い方

Last updated at Posted at 2014-07-14

データフレームに専攻しているので、それに直さなければならない。

library(ggplot2)

A <- data.frame(x=0:5,y=0:5)
B <- data.frame(x=(seq(from=0, to=10, by=1)), y=(seq(from=0, to=5, by=0.5)))
C <- data.frame(x=(seq(from=0, to=5, by=0.5)), y=(seq(from=0, to=10, by=1)))

new.df<-rbind(A,B,C)

色の分け方:オートでやってくれる。だがその前にデータフレームにID をつける。

new.df$ID<-rep(c("A","B","C"),c(nrow(A),nrow(B),nrow(C)))

なぜかファイルのセーブ方法が違う。ggsave を使え。

    ggsave(filename = fileTitle)

プロットの描写は以下のようにする。

    ggplot(new.df,aes(x,y,color=ID) )+geom_line() +labs(title = plotTitle ,x= xname, y = yname)

このように、データの長さが違ってもきっちり描写してくれる。
文字化けがおこる。文字化けノートを参照。

ちなみに、geom_path()をgeom_line()の代わりに使うと、点を関数になるように勝手にソートせずに、トラジェクトリーをそのまんま描いてくれる。

    ggplot(new.df,aes(x,y,color=ID) )+geom_path() +labs(title = plotTitle ,x= xname, y = yname)

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