2012-11-25 73 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

相關問題