2016-09-20 8 views
2

私はまだRの初心者です。グラフストリップチャートを作成する際に助けを求めたいと思います。グループ別のストリップチャートR

stripchart(Study_intensive$AGE, method="stack", 
at=c(0.05), pch=20, cex=2, xaxt="n", frame.plot=F, main= "Age Range in weight group(yr)") 
axis(1, at=seq(0, 75, by=5) , labels= seq(0, 75, by=5), 
cex.axis=0.75) 

これは現時点での私のコードで、「weightclass」という別の列でグループ化しようとしています。基本的に、各重みクラスに別の色を使用します。 "weightclass"は4つの値を持っています:1,2,3,4それぞれ。私は簡単にそうすることができますか?

ありがとうございました!

答えて

1

はここmtcarsを使用した例です:

library(RColorBrewer) 
testColor=brewer.pal(6, 'RdBu') 
stripchart(mtcars$mpg~mtcars$gear, col=testColor, method="stack", pch=20, cex=2, xaxt="n", frame.plot=F, main= "Age Range in weight group(yr)") 
axis(1, at=seq(0, 75, by=5) , labels= seq(0, 75, by=5), cex.axis=0.75) 

EDIT-1

使用すると、1つのストリップですべてを求めたものを取得する方法のビットがあります ggplot

とグループによって着色:

library(ggplot2) 
library(RColorBrewer) 
testColor=brewer.pal(6, 'RdBu') 
mtcars$color=testColor[mtcars$gear] #to get the colors your after 
mtcars$strip=1 #to get them into a single strip 
ggplot(mtcars, aes(x=strip, y=mpg, color=color)) + 
    geom_jitter(position=position_jitter(0.2)) + xlim(0, 2) 
+0

ありがとうございます!異なるギアが互いに重なり合うようにする方法はありますか? – Monklife

+0

@Monklife、 'ggplot'で編集してみてください。それがうまくいくなら、すべての設定が必要です。 – desc