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.
Thank you.
Elaine
Code
dataN <-read.csv("H:/skin_color.csv",header=T, row.names=1)
dim(dataN)
dataN[1,]
str(dataN)
obs.group<-dataN$skin_color
levels(dataN$skin_color) <- skin.code
skin.code <- c("White", "Yellow", "Red")
# graph
par(mai=c(1.03,1.03,0.4,0.4))
par(new=T)
plot(dataN$skin_color, dataN$body_length,
xlab="Skin Color",
ylab="Body Lenght",
xaxt="n",
type="p",
pch=1,lwd=2.0,
cex.lab=1.4, cex.axis=1.2,
font.axis=2,
cex=1.5,
las=1,
bty="l",
col=c("gray38","orange","red2")[obs.group])
[[alternative HTML version deleted]]
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