這是我的資料框資料
輸入(資料4)
structure(list(`number of goals scored` = c(311, 271),
`number of fouls commited` = c(2147, 2246)),
row.names = c("Hometeam", "AwayTeam"),
class = "data.frame")
這是我的條形圖代碼和創建分組條形圖時出現的錯誤
barplot(data4,
main = 'total num of goals and fouls commited',
xlab = 'Teams',ylab = 'frequency',
col = c('red','yellow'),
legend.text = rownames(data4),
beside = TRUE)
barplot.default 中的錯誤(data4,main = “總進球數和犯規數”,:“高度”必須是向量或矩陣
uj5u.com熱心網友回復:
看看這是不是你想要的:
barplot(as.matrix(data4[,1:2]),
main = 'total num of goals and fouls commited',
xlab = 'Teams',ylab = 'frequency',
col = c('red','yellow'),
legend.text = rownames(data4),
beside = TRUE)
barplot在第一個引數中要求一個矩陣。所以給它一個矩陣而不是 a data.frame。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/409470.html
標籤:
下一篇:根據新列值合并兩個資料框
