2012-02-21 16 views
0

Iの代わりにIポイントを着色する線を着色する以外は、実施例で着色点(R)I

http://www.ling.upenn.edu/~joseff/rstudy/week4.html#interactionplot

としてRにおける相互作用プロットを作成したいですその数字以外の属性によって。目的の機能が色を除き

blood_pressure = ... # this will be the x-axis 
age_bucket = ... # this will be the interaction-level 
gender = ... # color boys blue, girls red 
stroke_rate = ... # y-axis 

interaction.plot(blood_pressure, age_bucket, stroke_rate, col=gender, type="b"... 

のようになります=性別は実際に私が欲しいもの

答えて

1

を行い、問題がinteraction.plotが実際に集約要約指標を(平均値または中央値)を計算するためにtapply()に依存しているということです。 interaction.plotmatplotと呼ばれていますので、好きな場合は後者を直接使用するか、plyrでデータを要約し、結果をggplot2(もっと柔軟に)プロットしてください。要するに

# consider the 64x4 dataset OrchardSprays and create a fake 
# two-levels factor, say grp, which is in correspondence to rowpos odd/even values 
grp <- gl(2, 1, 8, labels=letters[1:2]) 
# the following won't work (due to color recycling) 
with(OrchardSprays, 
    interaction.plot(treatment, rowpos, decrease, 
         type="b", pch=19, lty=1, col=as.numeric(colpos), legend=F)) 
# what is used to draw the 8 lines is computed from 
with(OrchardSprays, 
    tapply(decrease, list(treatment=treatment, rowpos=rowpos), mean)) 
# the following will work, though 
with(OrchardSprays, 
    interaction.plot(treatment, rowpos, decrease, 
         type="b", pch=19, lty=1, col=as.numeric(grp), legend=F)) 

、あなたがgenderとあなたのトレースファクタ(age_bucket)との間に適切なマッピングを見つけることができると仮定すると、あなたはサイズnlevels(age_bucket)の色のベクターを構築する必要があります。