Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R GGplot-未找到目标序列_R_Ggplot2 - Fatal编程技术网

R GGplot-未找到目标序列

R GGplot-未找到目标序列,r,ggplot2,R,Ggplot2,我正在学习如何使用R,但似乎无法显示条形图。感觉我犯了一个新手级的错误 代码如下: > library(ggplot2) > ggplot(train, aes(Q2)) + geom_bar(fill = "red")+theme_bw()+ + scale_x_continuous("Age Brackets", breaks = seq("Under 18","Prefer not to say")) + + scale_y_continuous("Count

我正在学习如何使用R,但似乎无法显示条形图。感觉我犯了一个新手级的错误

代码如下:

> library(ggplot2)
> ggplot(train, aes(Q2)) + geom_bar(fill = "red")+theme_bw()+
+     scale_x_continuous("Age Brackets", breaks = seq("Under 18","Prefer not to say")) + 
+     scale_y_continuous("Count", breaks = seq(0,200,5)) +
+     coord_flip()+ labs(title = "Q2 - Age Brackets") + theme_gray()
以下是错误:

Error in ggplot(train, aes(Q2)) : object 'train' not found
SPSS文件:

RStudio中的Q2

RStudio环境中的数据和功能:



函数希望您要打印的数据名为
train
。您的环境中应该有一个名为
train
data.frame
。是吗?

函数希望要打印的数据名为
train
。您的环境中应该有一个名为
train
data.frame
。您是否?

是否已将文件读入R?请尝试
foreign
包中的
read.spss
函数或
Hmisc
包中的
spss.get
函数。@Daniel我添加了其他屏幕截图。我相信该文件已被读入R中。在您的截图中@Matadeleo不是名为“train”的对象。另外请注意,您的数据(名为“data”)属于data.set类,而不是data.frame:)我遵循相同的教程并在这里结束。这就是你需要做的。读取csv,然后将数据帧设置为名为train的变量
train您是否已将文件读入R?尝试
read.spss
函数(在
foreign
包中)或
spss.get
函数(在
Hmisc
包中)。@Daniel我添加了其他屏幕截图。我相信该文件已被读入R中。在您的截图中@Matadeleo不是名为“train”的对象。另外请注意,您的数据(名为“data”)属于data.set类,而不是data.frame:)我遵循相同的教程并在这里结束。这就是你需要做的。读取csv,然后将数据帧设置为名为train的变量<代码>在环境中训练我有一个
数据。set
,如果我为
数据更改
训练
。set
我得到错误:
if(is.aveage(data)| | empty(data))return(cbind(data,PANEL=integer(0)):缺少需要TRUE/FALSE的值
@Matadeleo
什么是
放弃(data)
空(data)
return?@ruibradas tware return`找不到函数“您的屏幕截图显示
数据。set
是一个函数。您的
ggplot
数据,您要替换的
train
应该在
data
部分,其类型应该是
data.frame
@Matadeleo,因此它们必须来自外部包,而不是
base R
包。您应该使用
library(pkgname)
启动脚本。在环境中,我有一个
data.set
,如果我将
train
更改为
data.set
我会得到错误:
if中的错误(is.aveage(data)| empty(data))返回(cbind(data,PANEL=integer(0))):缺少需要TRUE/FALSE的值
@Matadeleo所做的
是什么。放弃(数据)
空(数据)
返回?@Ruibradas都返回`找不到函数“您的屏幕截图显示
数据。set
是一个函数。您的
ggplot
数据,您要替换的
train
应该在
data
部分,其类型应该是
data.frame
@Matadeleo,因此它们必须来自外部包,而不是
base R
包。应该使用
库(pkgname)
启动脚本。