Mikkel Astrup
Mikkel Astrup

Reputation: 415

Change xaxis label to specific letters R

Im making a lot of plots in R and a part of my code looks like this:

plot(x=0,y=0, type="n", ylim=c(0,250), xlim=c(0,8), bty="n", main = "Line 20 male 3 sec rep 2", 
     xlab = "Concentration", ylab = "MM above buttom")
fc <- levels(dat20m2$Conc)
for(i in 1:length(fc)){
  tmp <- dat20m2[dat20m2$Conc==fc[i],]
  points(y=tmp$t30.sum,x=rep(i,length(tmp$t30)))
  points(y=mean(tmp$t30.sum),x=i,col="red")
}
abline(lm(t30.sum~as.integer(Conc),data=dat20m2), lty=2)

My x axis is from 0:8 but what i would like it to be is A, B, C, D, E, X, Y and i can make it work with the alphabet but when i wanna jump some letters i get into troubles. Can someone help me with that?

Upvotes: 0

Views: 64

Answers (1)

DarrenRhodes
DarrenRhodes

Reputation: 1503

plot(x=0,y=0, type="n", ylim=c(0,250), xlim=c(0,8), bty="n", main = "Line 20 male 3 sec rep 2", 
     xlab = "Concentration", ylab = "MM above buttom", xaxt="n")

## added xaxt="n"
## and the axis code below
axis(1,at=0:7,labels=c("0","A","B","C","D","E","X","Y"))
fc <- levels(dat20m2$Conc)
for(i in 1:length(fc)){
  tmp <- dat20m2[dat20m2$Conc==fc[i],]
  points(y=tmp$t30.sum,x=rep(i,length(tmp$t30)))
  points(y=mean(tmp$t30.sum),x=i,col="red")
}
abline(lm(t30.sum~as.integer(Conc),data=dat20m2), lty=2)

I got the answer from here and I've amended your code by adding the two parts described by the double pound signs. Hope this helps.

Upvotes: 1

Related Questions