用R语言和这个数据绘制折线图,不要ggplot2
时间: 2024-12-23 09:15:48 浏览: 14
好的,我可以帮助你使用基础的R绘图函数来绘制折线图。以下是根据提供的数据绘制折线图的代码:
```r
# 数据
stage <- c("Vegetative", "Reproductive")
growth_rate <- c(3, 20)
interval <- c(10, 7)
fertilizer_rate <- c(50, 80)
# 创建一个数据框
data <- data.frame(
Stage = stage,
GrowthRate = growth_rate,
FertilizationInterval = interval,
FertilizerRate = fertilizer_rate
)
# 绘制生长速率的折线图
plot(data$Stage, data$GrowthRate, type = "o", pch = 19, lwd = 2, col = "blue",
xlab = "Growth Stage", ylab = "Growth Rate (cm/week or cm)",
main = "Iris Plant Growth Data")
# 添加注释
text(data$Stage, data$GrowthRate + 1, labels = paste(data$GrowthRate, "cm"), pos = 3, col = "red")
# 绘制施肥间隔的折线图
lines(data$Stage, data$FertilizationInterval, type = "o", pch = 17, lwd = 2, col = "green")
# 添加注释
text(data$Stage, data$FertilizationInterval + 1, labels = paste(data$FertilizationInterval, "days"), pos = 3, col = "green")
# 绘制复合肥料施用量的折线图
lines(data$Stage, data$FertilizerRate, type = "o", pch = 15, lwd = 2, col = "purple")
# 添加注释
text(data$Stage, data$FertilizerRate + 1, labels = paste(data$FertilizerRate, "g/m^2"), pos = 3, col = "purple")
# 添加图例
legend("topright", legend = c("Growth Rate", "Fertilization Interval", "Fertilizer Rate"),
col = c("blue", "green", "purple"), pch = c(19, 17, 15), lty = 1, lwd = 2)
```
这段代码将创建一个包含三个变量(生长速率、施肥间隔和复合肥料施用量)的折线图,并在每个点旁边添加相应的数值标签。希望这对你有帮助!
阅读全文