2016-01-23 82 views
0

我現在用的是以下幾行,以產生兩個4X10矩陣D1的行下面的情節,和D2在一個圖表:分配標籤只在劇情有些數據點

plot(as.matrix(d1[2,]), as.matrix(d2[2,]), type="o", col="firebrick", ann=FALSE, pch=17, log = 'y',lty=4, xaxt = "n", yaxt="n", las=2, ylim = c(50, 2e6))+ 
lines(as.matrix(d1[1,]),as.matrix(d2[1,]), type="o", col="deepskyblue", ann=FALSE, pch=15, lty=4)+ 
lines(as.matrix(d1[3,]),as.matrix(d2[3,]), type="o", col="darkorange", ann=FALSE, pch=18, lty=4)+ 
lines(as.matrix(d1[4,]),as.matrix(d2[4,]), type="o", col="lawngreen", ann=FALSE, pch=16, lty=4) 

x_axis_range <- c(0, 1, 2, 4, 6, 8, 10, 12, 14) 
axis(1,at = x_axis_range, labels = x_axis_range) 
axis(1,at = x_axis_range, labels = x_axis_range) 

y_axis_range <- c(1e+2, 4e+2, 1e+3, 5e+3, 3e+4, 2e+5, 5e+5, 2e+6) 
y_axis_labels <- c("100", "400", "1K", "5K", "30K", "200K", "500", "2M") 
axis(2,at = y_axis_range, labels = y_axis_labels, las=2) 

而且它產生的下圖:

enter image description here

有沒有一種方法來標記第一個和最後數據點,每行一個任意標籤(即「F」和「L」)?

回答

0

以供將來參考,這個答案是:

text(as.matrix(d1[3,2]),as.matrix(d2[3,2]) , labels=c("F"), pos = c(4), cex=0.8) 
text(as.matrix(d1[3,10]),as.matrix(d2[3,10]) , labels=c("L"))), pos = c(4), cex = 0.8) 
2

下面是一個應該給你的想法的例子。

DF <- data.frame(x = 1:10, y = (1:10)^2) 
plot(DF$x, DF$y, type = "b") 
last <- nrow(DF) 
text(DF$x[c(1, last)], DF$y[c(1, last)], labels = c("F", "L"), pos = c(3, 4))