[R] Plot with a factor variable which has large values

Jim Lemon jim at bitwrit.com.au
Fri Dec 18 09:07:47 CET 2009


On 12/18/2009 06:42 AM, changzhu wrote:
> I wanted to do a simple plot: Death Rate vs Clinical Site, and then draw a
> confidence interval of Death Rate at each clinical site, which is a factor
> variable with 100 levels. I used the following code:
>
> plot(Site, Rate, col="red", type="o")
>
> However, the graph was a short line at each site instead of points, and the
> color was not red at all. Seem to me for factor variable all options are not
> working ! Could anybody help me on how  to draw points at each site, with
> specific color? if possible, how to further draw confidence interval at each
> site?
>    
Hi Changzu,
Since I don't have Site or Rate, I'll have to be imaginative:

Site<-paste(sample(LETTERS,100,TRUE),
  sample(letters,100,TRUE),sep="")
SiteOrder<-order(Site)
Rate<-runif(100)
plot(as.numeric(factor(Site))[SiteOrder],
  Rate[SiteOrder],col="red",type="o")

Having performed that chicanery, I feel justified in telling you to use 
the dispersion function in the plotrix package for the CIs, although 
there are many other similar functions.

Jim




More information about the R-help mailing list