The MyData data is shown below:
#在同一张图中画多条折线图并添加图例rm (list = ls (all = TRUE))
MyData <-read.csv ("Test.csv", Header = TRUE)
Spring_data <-Mydata[which (Mydata$season = = "Spring"),]
X_names <-As.vector (spring_data$name)
Plot (Spring_data$one,col = "Black", pch = 1,type = "O", Xlab = "x", Ylab = "Y", Ylim = C (0.0,1.0), axes = FALSE)
Lines (Spring_data$two,col = "Black", pch = 2,type = "O")
Lines (Spring_data$three,col = "Black", pch = 8,type = "O")
#这里先用axis设置x轴的刻度和标签, where the label is represented by a space "" to automatically set the x-axis scale that can rotate the angle with the text function
Axis (side = 1,at = Seq (1,7,by = 1), labels = C ("", "", "," "," ",", ""))
Axis (side = 2,at = Seq (0.0,1.0,0.1), labels = seq (0.0,1.0,0.1))
#用text函数自动设置可以旋转角度的x轴刻度
Text (x=seq = 1), y = -0.08, srt = 1,7,by, adj = 1, labels = X_NAMES,XPD = TRUE)
# #验证x轴刻度是否为1-7
# for (num_i in 1:7)
# {
# abline (v = num_i, col = "green")
# }
Summer_data <-Mydata[which (Mydata$season = = "Summer"),]
Lines (Summer_data$one,col = "Red", pch = 1,type = "O")
Lines (Summer_data$two,col = "Red", pch = 2,type = "O")
Lines (Summer_data$three,col = "Red", pch = 8,type = "O")
Autumn_data <-Mydata[which (Mydata$season = = "Autumn"),]
Lines (Autumn_data$one,col = "Magenta", pch = 1,type = "O")
Lines (Autumn_data$two,col = "Magenta", pch = 2,type = "O")
Lines (Autumn_data$three,col = "Magenta", pch = 8,type = "O")
Winter_data <-Mydata[which (Mydata$season = = "Winter"),]
Lines (Winter_data$one,col = "Blue", pch = 1,type = "O")
Lines (Winter_data$two,col = "Blue", pch = 2,type = "O")
Lines (Winter_data$three,col = "Blue", pch = 8,type = "O")
#加图例
Legend (0.85,0.7,c ("One", "two", "three"), Pt.cex = 1.7, PCH = C (1,2,8), CeX = 1.3, Bty = "n")
Legend (0.78,0.4,c ("Spring", "Summer", "Autumn", "Winter"),
Fill = C ("Black", "red", "magenta", "blue"), border = FALSE,
Col = C ("Black", "red", "magenta", "blue"), Pt.cex = 1.7, CeX = 1.3, Bty = "n")
The drawing is as follows: