Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/68.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 - Fatal编程技术网

R ggplot抱怨对数据应用代码

R ggplot抱怨对数据应用代码,r,R,我有个奇怪的问题,我自己解决不了 我的原始数据就是这样的: > dput(df[1:25]) structure(c(2, 2, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 2, 3, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1), .Names = c("AT1G01050", "AT1G01090", "AT1G01320", "AT1G01470", "AT1G01560", "AT1G02150", "AT1G02560", "AT1G02

我有个奇怪的问题,我自己解决不了

我的原始数据就是这样的:

> dput(df[1:25])
structure(c(2, 2, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 2, 3, 1, 2, 
1, 1, 1, 1, 1, 2, 1, 1), .Names = c("AT1G01050", "AT1G01090", 
"AT1G01320", "AT1G01470", "AT1G01560", "AT1G02150", "AT1G02560", 
"AT1G02780", "AT1G02920", "AT1G03090", "AT1G03130", "AT1G03220", 
"AT1G03230", "AT1G03330", "AT1G03630", "AT1G03680", "AT1G03870", 
"AT1G04080", "AT1G04170", "AT1G04270", "AT1G04410", "AT1G04480", 
"AT1G04690", "AT1G04710", "AT1G04810"))
我尝试使用以下函数创建ggplot:

dat <- as.data.frame(df[1:25]))
dat$factor <-1
ggplot(dat,aes(x=factor,fill=factor(dat))) +
  geom_bar(binwidth=5) +
  coord_flip()
但是

当我尝试在示例数据上使用相同的代码时,它具有完全相同的(至少在我看来)结构,昨天它工作得很好,但现在它没有。。。这两个数据集都称为
命名数字

> dput(data)
structure(c(2, 8, 3, 4, 1, 2, 3, 5, 4, 7, 6, 4, 1), .Names = c("Mark", 
"Greg", "Sonya", "Monica", "Tiana", "Arra", "Armin", "Hera", 
"Cyrus", "Pier", "Tina", "Hector", "Markus"))

我使用了您的示例数据,但两者都适用。我相信这就是你想要的:

dat <- as.data.frame(data)
dat$factor <-1
ggplot(dat,aes(x=as.numeric(factor),fill=factor(dat[,1]))) + geom_bar(binwidth=5) + coord_flip()

dat也许您应该尝试更改数据的名称,或者尝试在data.frame上使用factor函数。您只能在矢量上使用系数
?系数
将帮助您在此
ggplot
上使用数据名称,您不希望这样做
dat <- as.data.frame(data)
dat$factor <-1
ggplot(dat,aes(x=as.numeric(factor),fill=factor(dat[,1]))) + geom_bar(binwidth=5) + coord_flip()