我有一个奇怪的问题,我无法自己解决。
我原始数据的样子如下:
> 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()
因此我收到了这个错误:
Error in sort.list(y) : 'x' must be atomic for 'sort.list'
Have you called 'sort' on a list?
但是...
当我尝试在具有完全相同(至少在我看来)结构的示例数据上使用相同的代码时,它昨天工作正常,但现在它没有...两个数据集都被称为Named numeric
:
> 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"))
答案 0 :(得分:0)
我使用了您的示例数据,但两者都运行良好。我相信你正在寻找的东西:
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()