2
我有我自己無法解決的奇怪問題。ggplot抱怨將代碼應用到數據中
那是我最初的數據看起來像:
> 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"))
也許你應該試着改變數據的名稱或試試這個'補=係數(係數)' –
你想上使用因子功能data.frame。你可以使用因子只有向量'?因子'會幫助你在這個 – Sivaji