Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 204715

Plotting a chessboard in R. How to name columns and rows?

$
0
0

I wrote the function, that draws chessboards. I want to name each column and row using the letters. But, I don't know how to do this.

My code:

chessboard=function(n){
  if(1<=n & n<=26){
    x=c(1:(n+1))
    y=c(1:(n+1))

    plot(x,y,type="n", yaxt='n',xaxt='n', ann=FALSE)
    for (i in (1:n)) {
      if(i%%2==0){
        col=c("#FFFFFF","#000000")
      }
      else{
        col=c("#000000","#FFFFFF")
        }
      rect(i,1:(n+1),i+1,(n+1), col=col, )
    }
  } 
  else{
    print("wrong!")
  }
  }

Now I have : enter image description here

But, I want to have: enter image description here


Viewing all articles
Browse latest Browse all 204715

Trending Articles