3

我在网上找到了一个代码,它必须(将)生成一个代表美国劳工部的一些数据的图形:劳工统计局:

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' 包含来自此处的数据,生成的图形必须如下所示

4

2 回答 2

5

出现错误是因为没有任何名为“日期”和“比率”的变量。这工作正常:

 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")
于 2012-11-25T12:53:00.560 回答
0

像这样的https://stackoverflow.com/questions/16201906/how-can-i-get-the-value-of-a-kernel-density-estimate-at-specific-points可能对其他人有用周围的热图。

于 2013-11-13T01:34:48.740 回答