Help us understand the problem. What is going on with this article?

R: ggplot2 使い方

More than 5 years have passed since last update.

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

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)

http://docs.ggplot2.org/current/geom_line.html

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away