首页 > 解决方案 > ggplot2 for R 中的主题 _stata 是否仍然可用?我收到一条错误消息

问题描述

我想theme_stata用于我的 ggplot。使用以下代码,一切正常,除了主题:

df3 <- data_summary(panel_data, 
                    varname = "invest_amnt", 
                    groupnames = c("trend_id", "path_id")
)

df3$path_id <- as.factor(df3$path_id)
df3$trend_id <- as.factor(df3$trend_id)

head(df3)
  
df.mean <- df3 %>% 
  group_by(path_id) %>% 
  mutate(ymean = mean(invest_amnt))
     
p <- ggplot(df3, aes(x = path_id, y = invest_amnt, fill = trend_id)) + 
  geom_bar(stat = "identity", position = position_dodge()) +
  geom_errorbar(aes(ymin = invest_amnt-sd, ymax = invest_amnt+sd), 
                width=.2, position=position_dodge(.9))
      
p + 
  scale_fill_brewer(palette = "Paired") + 
  theme_stata() + 
  scale_color_stata()
    
p + 
  labs(title = "", x = "path)", y = "Invested Amount") +
  scale_fill_manual(values = c('#f55b5b','#23036b','#e3d613' )) +
  theme_classic() +
  geom_errorbar(data = df.mean, aes(x = path_id , ymax = ymean, ymin = ymean),
                size=1.5, linetype = "longdash", inherit.aes = F, width = 1)

我收到以下错误消息:

Error in theme_stata() : could not find function "theme_stata"

标签: rggplot2

解决方案


theme_stata()ggthemes package的一部分。该软件包应加载library(ggthemes).


推荐阅读