[R] Change color of plot points based on values of a variable

Josip Dasovic jjd9 at sfu.ca
Wed Oct 1 09:22:06 CEST 2008


Dear R users:

I have run a logistic regression, used Gelman et al.'s car package to simulate the parameter estimates of that model, and have plotted the probability (using Gelman et al.'s invlogit() function) of the dependent variable being 1 given the value of a particular independent variable is at its mean.  The plot has probabilities on the y-axis and the number (1-1000) of the simulation run on the x-axis.  

What I would like to do is to make the points that make up the 95% CI a different color from the points outside that CI.  In other words, I would like the points from 1-24, and 976-1000 to be one color (the default color is fine), and the points 25-975 to be a different color. How would I do this?

In case there is some confusion, here is example code, with only one predictor:

set.seed(23)
y<-rbinom(100,1,0.1)
x<-rnorm(100)
fit.1<-glm(y~x1, family=binomial(link="logit"))
library(car)
sim.fit.1<-sim(fit.1, 1000)   #Simulate the parameter estimates of fit.1 1000 times
plot(sort(invlogit(sim.fit.1$beta[,1]+sim.fit.2$beta[,2]*mean(x1))))


Thanks, 
Josip



More information about the R-help mailing list