我在 R 中的绘图功能有问题。这是我到目前为止得到的。
countries <- c("CHINA ", "UNITED STATES", "UNITED KINGDOM", "GERMANY")
KeyItems <- c("Pretax Income", "Total Liabilities", "Total Assets")
datA <- mean_values[mean_values$Country %in% countries & mean_values$KeyItem %in% KeyItems, ]
datA$KeyItem <- factor(datA$KeyItem, levels = KeyItems, order = TRUE)
p <- xyplot(mn_value ~ Year | KeyItem, datA, groups = datA$Country[, drop = TRUE],
auto.key = list(space = "right"), par.settings = simpleTheme(pch = 1:5),
type = c("p", "l"), as.table = TRUE)
print(p)
我的数据框如下所示:
KeyItem Year Country mn_value
172 Pretax Income 1980 SWITZERLAND 2.091623e+08
173 Pretax Income 1980 IRELAND 3.597619e+07
174 Pretax Income 1980 GERMANY 2.301015e+07
175 Pretax Income 1980 SWEDEN 4.980680e+07
它返回此错误:
Error in dat$Year == Year : 'Year' is missing
我在 R 方面几乎没有任何经验。我只是找不到解决问题的方法。先感谢您。