r - Label on X-axis for each group of points -


i'm creating script allows me data database, , visualises in graph. enter image description here

as can see, there 8 groups of data, indicated on x-axis. each group contains 90 values.

right now, place of labels hard-coded this:

axis(1, @ = c(31.25, 93.75, 156.25, 218.75, 281.25, 343.75, 406.25, 468.75),      labels = c("ss oligo 1", "ss oligo 2", "ss oligo 3", "ss oligo 4",                 "ss oligo 4", "ss oligo 5", "ss oligo 6", "ss oligo 7")) 

it works fine, wondering if there way more dynamically, telling r assign label each set of 90 values.

example:

# generate data ################################################################################### x <- vector() y <- vector()  # y[length(y)+1] <- sample(10:12, 1, replace = true) oligo_1 <- runif(62, 10.5, 11.5) oligo_2 <- runif(62, 14, 15) oligo_3 <- runif(62, 17, 18) oligo_4a <- runif(64, 20.5, 22) oligo_4b <- runif(64, 20.5, 22) oligo_5 <- runif(62, 24, 25) oligo_6 <- runif(62, 27, 28) oligo_7 <- runif(62, 30, 31)  y <- c(oligo_1, oligo_2, oligo_3, oligo_4a, oligo_4b, oligo_5, oligo_6, oligo_7) x <- c(1:500)  example <- data.frame(x, y)  # define variables ################################################################################ xmin      <- 10 xmax      <- 36  # generate graph ################################################################################### png(filename = "graph.png", width = 1500, height = 833)  plot(x = example[,2], type="l",      xlim = c(0, nrow(example)), ylim = c(xmin, xmax),      xaxt="n", yaxt="n",      xlab = "", ylab = "")  rect(xleft = par("usr")[1], ybottom =  9.8, xright = par("usr")[2], ytop = 12.2, border = "lightgrey", col = "lightgrey") rect(xleft = par("usr")[1], ybottom = 13.2, xright = par("usr")[2], ytop = 15.5, border = "lightgrey", col = "lightgrey") rect(xleft = par("usr")[1], ybottom = 16.5, xright = par("usr")[2], ytop = 18.9, border = "lightgrey", col = "lightgrey") rect(xleft = par("usr")[1], ybottom = 19.9, xright = par("usr")[2], ytop = 22.3, border = "lightgrey", col = "lightgrey") rect(xleft = par("usr")[1], ybottom = 23.3, xright = par("usr")[2], ytop = 25.5, border = "lightgrey", col = "lightgrey") rect(xleft = par("usr")[1], ybottom = 26.5, xright = par("usr")[2], ytop = 28.7, border = "lightgrey", col = "lightgrey") rect(xleft = par("usr")[1], ybottom = 29.7, xright = par("usr")[2], ytop = 32.1, border = "lightgrey", col = "lightgrey")  axis(1, @ = c(31.25, 93.75, 156.25, 218.75, 281.25, 343.75, 406.25, 468.75),       labels = c("ss oligo 1", "ss oligo 2", "ss oligo 3", "ss oligo 4",                  "ss oligo 4", "ss oligo 5", "ss oligo 6", "ss oligo 7")) axis(2, @ = c(11, 14.35, 17.7, 21.1, 24.4, 27.6, 30.9), las = 1)  lines(x = example[,2]) box()  mtext(paste("qc-check for", "test"), side = "3", line = 1, cex = 2, font = 2) mtext("samples"                       , side = "1", line = 3, cex = 1, font = 1)  legend(x = par("usr")[1]+10, y = par("usr")[4]-1, legend = c("cq", "ccq"), cex=1.5, lwd = 2, col = c("black","red"))  dev.off() 

why not:

axis(1, at=31.25+(0:7)*62.5, labels=paste("ss oligo",1:8) ) 

Comments

Popular posts from this blog

python - matpltolib navigation toolbar edit curves and parameters line color automatically changes issue -

node.js - Nodejs javascript implementation of PBEWithMD5AndTripleDES/CBC/PKCS5Padding -