gpt4 book ai didi

r - ggplot2 错误 : object 'ratio' not found

转载 作者:行者123 更新时间:2023-12-01 11:48:56 31 4
gpt4 key购买 nike

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

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 .

最佳答案

出现错误是因为没有任何名为“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")

关于r - ggplot2 错误 : object 'ratio' not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13551073/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com