Data structure

D=cbind(pos, chr, pVal);

Plot argument

mini=aggregate(pos~chr,data=D,min)
maxi=aggregate(pos~chr,data=D,max)

# where to put chr number 
at=round((mini+maxi)/2)

# index color by chr
col=rainbow(23)
plot(pos,Pval,col=col[chr],xaxt='n',xlab='',ylab='',cex.axis=1)

# add chr axis
axis(side=1,at=at[,1],labels=a[,2],cex.axis=1)
mtext("Chromosome", side=1, line=2,cex=1)
mtext(expression(-log[10]^P), side=2, line=2,cex=1)

Expression{plotmath} in R

Link

Color generator (H Wu., 2016)

n_col <- 6
color_idx <- rep(NA, n_col^2)
 
for(i in 1:n_col^2){
	
	r = sample(255,1)
	g = sample(255,1)
	b = sample(255,1)
	
	color_idx[i] <- rgb(r,g,b, max=255)  
}

plot(sort(rep(1:n_col,n_col)), rep(1:n_col,n_col), 
	xlim=c(0.5,n_col+0.5), ylim=c(0.5,n_col+0.5),
	col=color_idx[1:n_col^2], 
	pch=19, cex=(13-n_col), 
	xlab='', ylab='')

text(sort(rep(1:n_col,n_col)), rep(1:n_col,n_col), 1:n_col^2)

color_idx