我使用以下两行来从两个4X10 Matrix 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)
它产生以下图表:
有没有办法用任意标签(即“F”和“L”)标记每一行的第一个和最后一个数据点?
答案 0 :(得分: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))
答案 1 :(得分: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)