[R] add categorical labels in plot

Jim Lemon jim at bitwrit.com.au
Sat Jan 12 10:45:18 CET 2013


On 01/12/2013 12:01 PM, Elaine Kuo wrote:
> Hello
>
> I want to draw a plot using the code below.
>
> Further, I want to add labels (White, Yellow, Red) to x-axis.
> Please kindly advise how to add the categorical labels, by modifying the
> code.
>...

Hi Elaine,
Bit hard to tell exactly what you want, but try this:

ek.data<-data.frame(
  skin_color=sample(c("white","yellow","red"),100,TRUE),
  body_length=runif(100,80,120))
skin.colors<-c("white","yellow","red")
plot(as.numeric(ek.data$skin_color),ek.data$body_length,
  bg=skin.colors[as.numeric(ek.data$skin_color)],pch=21,
  xlim=c(0.5,3.5),xaxt="n")
axis(1,at=1:3,labels=skin.colors)

Jim




More information about the R-help mailing list