1
我想在x轴上绘制这个数据框。用xyplot绘制月度数据R
month value1 value2 value3 value4
1 Okt 19.5505 19.6145 19.5925 19.3710
2 Nov 21.8750 21.7815 21.7995 20.5445
3 Dez 25.4335 25.2230 25.2800 22.7500
t = read.csv("Mappe1.csv", header = TRUE, sep=";", dec = ".", fill = TRUE, comment.char = "")
t$m <- factor(t$m, levels = c("Okt", "Nov", "Dez"))
library(Hmisc)
xyplot(t$value1~t$m, type = "l", col = "red", ylab="values")
lines(t$value2~t$m, type = "l", col = "cyan")
lines(t$value3~t$m, type = "l", col = "purple")
lines(t$value4~t$m, type = "l", col = "black", lwd = 2)
legend("topleft", legend=c("value1", "value2", "value3", "value4"),
col=c("red", "cyan", "purple", "black"), lty=1:1, cex=0.8)
它对这个例子很好。但是当我试图exactely方式相同,但具有不同的值,只有数值1 plottet,我总是得到以下错误:
Error in plot.xy(xy.coords(x, y), type = type, ...) :
plot.new has not been called yet
Error in strwidth(legend, units = "user", cex = cex, font = text.font) :
plot.new has not been called yet
我已经申请plot.new()和dev.off()。但有时我仍然会得到这些错误,或者有时候R不会显示错误,但根本不会显示。
这里有什么问题?
非常感谢您的帮助!
你混合网格(格子/ GGPLOT2)和碱的图形。使用一个或另一个。 –