【问题标题】:R attempt to replicate an object of type 'closure'R尝试复制“闭包”类型的对象
【发布时间】:2021-04-29 21:00:48
【问题描述】:

我正在尝试运行此代码,但出现此错误:

rep(x[[i]], n) 中的错误: 尝试复制“闭包”类型的对象

请帮助解决这个问题并告诉我我需要更改/添加到我的代码中的确切内容

monthyear = c('January 2015', 'February 2015', 'March 2016', 
              'April 2016', 'May 2016', 'June 2016', 'July 2016', 
              'January 2017', 'Februrary 2017', 
              'August 2017', 'September 2017', 'October 2017')

c_report = c(742, 3420, 4263, 5147, 6255, 93872, 2323, 
             4677, 9398, 2112, 1000, 7890)

o_report = c(30185, 33894, 33642, 29439, 27879 ,52347, 
             4578, 3639, 10000, 48781, 64484, 5020)

data.m <- melt(df, id.vars='dateyear')

ggplot(data.m, aes(dateyear, c_report)) +   
  geom_bar(aes(fill = o_report), position = "dodge", stat="identity") + theme(axis.text.x = element_text(angle = 90, hjust = 1))

谢谢

【问题讨论】:

  • 变量df从何而来?如果您的错误可以重现给其他人,这会有所帮助。

标签: r ggplot2


【解决方案1】:
monthyear = c('January 2015', 'February 2015', 'March 2016', 
              'April 2016', 'May 2016', 'June 2016', 'July 2016', 
              'January 2017', 'Februrary 2017', 
              'August 2017', 'September 2017', 'October 2017')

c_report = c(742, 3420, 4263, 5147, 6255, 93872, 2323, 
             4677, 9398, 2112, 1000, 7890)

o_report = c(30185, 33894, 33642, 29439, 27879 ,52347, 
             4578, 3639, 10000, 48781, 64484, 5020)

library(tidyverse)

df <- tibble(monthyear, c_report, o_report) %>% 
  mutate(dateyear = gsub("[A-Za-z ]", "", monthyear)) %>% 
  select(-monthyear) %>% 
  pivot_longer(-dateyear)

ggplot(df, aes(dateyear, value)) +   
  geom_bar(aes(fill = name), position = "dodge", stat="identity") + 
  theme(axis.text.x = element_text(angle = 90, hjust = 1))

【讨论】:

    猜你喜欢
    • 2019-07-16
    • 2013-07-15
    • 1970-01-01
    • 1970-01-01
    • 2013-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多