【发布时间】:2021-09-18 00:47:11
【问题描述】:
我正在尝试创建一个绘图栏,但我遇到了数据问题。数据来自“列表”,我将“列表”转换为“数据框”,但我有几个问题。首先是像“Sources ”这样的单词之后的空格,我认为也在 Sources “B”之后。当我运行代码时出现错误:abs(x) 中的错误。
我很高兴知道发生了什么,因为我无法制作图表。我认为问题可能出在这些地方。
代码
S <- summary(object = results, k = 10, pause = FALSE)
df <- S$MostRelSources
df <- df %>% dplyr::rename(Sources = `Sources `)
df$Sources <- as.character(df$Sources))
df$Articles <- as.numeric(df$Articles)
ggplot(df, aes(x=Sources, y=Articles)) +
geom_col()
Error in abs(x) : non-numeric argument to mathematical function
数据
dput(df)
structure(list(Sources = structure(c("A ",
"B ", "C ",
"D ", "E ",
"F ", "G",
"H ", "Y ",
"J "), class = "AsIs"),
Articles = c(1, 10, 7, 3, 3, 5, 5, 5, 2, 8)), row.names = c(NA,
10L), class = "data.frame")
【问题讨论】: