Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (5.3k points)
edited by

I would like to use theme_stata for my ggplot. Using the following code, everything works, except for the theme:

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) 

I get the following error message:

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

1 Answer

0 votes
by
edited by

In order for your code to work, you need to install the ggthemes package since theme_stata is a part of ggthemes package and not the ggplot2 package.

To install and load ggthemes package:

install.packages("ggthemes")

library("ggthemes")

Browse Categories

...