我正在創建一個腳本,它允許我從數據庫中獲取數據,並在圖形中將其可視化。 X軸上每組點的標籤
正如您所看到的,有8組數據,在X軸上顯示。每個組總是包含90個值。
眼下,標籤的地方是硬編碼是這樣的:
axis(1, at = 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"))
這工作完全正常,但我不知道是否有一種方法可以更動態地做到這一點,通過只是告訴[R爲每組90個值分配一個標籤。
例子:
# 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, at = 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, at = 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()
如果您提供一個[**最小的自包含示例**],它將更容易回答您的問題(http://stackoverflow.com/questions/5963269/how-to-make-a-大-R-重複性,例如/ 5963610#5963610)。 – Henrik
@ Hendrik:添加了示例 – Fingashpitzzz