2012-11-25 71 views
3

我在网上找到了一个代码,必须(将)产生表示来自美国劳工部门的一些数据图形:劳工统计局:GGPLOT2错误:对象“比”未找到

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 

此代码缺少什么?

'unemp.csv'包含来自here的数据,生成的图形必须看起来像this

回答

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") 
+0

阿图拉,非常感谢! – Iurie

相关问题