我在网上发现了一个代码,必须(将)生成代表美国劳工部:劳工统计局的一些数据的图形。:
library(ggplot2)
df <- as.data.frame(read.csv("unemp.csv", colClasses = c("Date", "numeric")))
p <- ggplot(df,aes(x=date,y=ratio))
p + geom_point() + geom_smooth() + xlab("Year") +
ylab("Civilian Employment Population Ratio (%)") +
labs(title="Bureau of Labor Statistics Series EMRATIO
(seasonally adjusted) to 2012-10-01")
但它不起作用并产生此错误:
Don't know how to automatically pick scale for object of type function. Defaulting to continuous
Error in eval(expr, envir, enclos) : object 'ratio' not found
此代码中缺少什么?
答案 0 :(得分:5)
出现错误是因为没有任何名为“date”和“ratio”的变量。这很好用:
library(ggplot2)
df <- as.data.frame(read.table("unemp.txt", header = TRUE, colClasses = c("Date", "numeric")))
names(df) <- c("date", "ratio")
p <- ggplot(df,aes(x=date,y=ratio))
p + geom_point() + geom_smooth() + xlab("Year") +
ylab("Civilian Employment Population Ratio (%)") +
labs(title="Bureau of Labor Statistics Series EMRATIO (seasonally adjusted) to 2012-10-01")
答案 1 :(得分:0)