2012-05-11 8 views
1

内の特定のインデックスでグループIは、私はこのようなデータセット持っR.でプログラムを書いている:プロットyの別の列対xの列、R

category x-value y-value 
     1  2  5 
     1  3  1 
     1  4  10 
     1  5  23 
     2  2  12 
     2  3  15 
     2  4  21 
     2  5  29 
     3  2  34 
     3  3  45 
     3  4  7 
     3  5  9 

をそして、私はシンプルを見つけたいですデータを「カテゴリ」でグループ化し、これら3つのデータセットを1つのxyplotにプロットする方法です。

ありがとうございます!

答えて

2

ggplot2を使用していますか? これは何か?

df = read.table(text = " 
category x-value y-value 
    1  2  5 
    1  3  1 
    1  4  10 
    1  5  23 
    2  2  12 
    2  3  15 
    2  4  21 
    2  5  29 
    3  2  34 
    3  3  45 
    3  4  7 
    3  5  9", header = TRUE, sep = "") 

library(ggplot2) 
ggplot(df, aes(x.value, y.value, colour = factor(category))) + geom_point() + 
    geom_path() 

enter image description here

ORこの?

ggplot(df, aes(x.value, y.value, shape = factor(category), 
colour = factor(category))) + geom_point(size = 5) 

enter image description here

+0

ありがとう!これはとても素敵です:)。もともと私はデータセットを分割するためにサブセット()を使用しようとしましたが、これはあなたが提供する方法ほどきれいではありませんでした。まだggplotで美しいグラフをプロットする方法を学ぶ。 – cchuang

+0

@ sprite728 [wiki.stdout.org/rcookbook/Graphs/](http://wiki.stdout.org/rcookbook/Graphs/)を読んでみてください。 –

関連する問題