r - How to color different groups in qqplot? -


i'm plotting q-q plots using qqplot function. it's convenient use, except want color data points based on ids. example:

library(qualitytools) n=(rnorm(n=500, m=1, sd=1) ) id=c(rep(1,250),rep(2,250)) mydata=data.frame(x=n,y=id) qqplot(mydata$x, "normal",confbounds = false) 

so plot looks like: enter image description here

i need color dots based on "id" values, example blue ones id=1, , red ones id=2. appreciate help.

not used qqplot before, want use it, there way achieve want. looks function invisibly passes data used in plot. means can this:

# use qqplot - generates graph, ignore plotdata <- qqplot(mydata$x, "normal",confbounds = false, col = sample(colors(), nrow(mydata)))  # given have data generated, can create own plot instead ... with(plotdata, {   plot(x, y, col = ifelse(id == 1, "red", "blue"))   abline(int, slope) }) 

hope helps.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

php - How do you embed a video into a custom theme on WordPress? -