0

This graph was working perfectly before, and now it is giving me the error "Error: object 'dodge' not found". It used to work perfectly fine, and I didn't change the code. Does someone have any idea of what could be going on?

Thank you.

Here is the code and what the graph used to look like.


library(lfe)
library(dplyr)
library(tidyverse)
library(broom)
library(data.table) 
library(lfe) 
library(texreg) # not working
library(hdm) 
library(parallel)
library(coefplot)
library(ggplot2)
library(GGally)
library(broom.helpers)
library(knitr)
library(ggplot2)
#library(devtools)
#devtools::install_github('cttobin/ggthemr')
library(ggthemr)
#devtools::install_github("thomasp85/patchwork")
library(patchwork)

################################################################################ 
#   Plot
################################################################################ 
plot_applied <- ggplot(results, 
                        aes(x = Outcome, y = Coefficient, color=Variable)) +
  geom_hline(yintercept = 0, 
             colour = gray(1/2), lty = 2) +
  geom_point(aes(x = Outcome, 
                 y = Coefficient, color=Variable, shape=Variable), show.legend = TRUE, size = 2.5, stroke = 1.2, position = position_dodge(width = dodge)) + 
  
  geom_linerange(aes(x = Outcome, 
                     ymin = conf.low_90,
                     ymax = conf.high_90, color=Variable),
                 lwd = 1, position = position_dodge(width = dodge), show.legend = TRUE) +
  geom_linerange(aes(x = Outcome, 
                     ymin = conf.low_95,
                     ymax = conf.high_95, color=Variable),
                 lwd = 1/2, position = position_dodge(width = dodge), show.legend = TRUE)+
  scale_x_discrete(limits=desired_order, labels = labels) + # bottom to top = left to right 
  scale_color_manual(values = c("#f5ad9f", "#91c8e3", "#226bb4"), name = "Treatment:", labels = c("Flyer: Complexity", "Flyer: Knowledge", "Welcome letter"), guide = guide_legend(reverse=T)) +
  scale_shape_manual(values = c(16, 17, 18), name = "Treatment:", labels = c("Flyer: Complexity", "Flyer: Knowledge", "Welcome letter"), guide = guide_legend(reverse=T)) +
  #scale_shape_manual(values = c(15, 21, 19), name = "Data source:", labels = c("Survey W2\n(N=2,551)", "Survey W1\n(N=3,859)")) +
  coord_flip()+
  theme_bw() +
  xlab(label = NULL) +
  ylim(-0.1,0.8)+
  theme(panel.border = element_blank()) +
  theme(text = element_text(size=12)) +
    theme(legend.position = "bottom")# +

plot_applied

I tried tracing back the error, and this is what I get.



> traceback()
5: list2(...)
4: ggproto(NULL, PositionDodge, width = width, preserve = arg_match0(preserve, 
       c("total", "single")))
3: position_dodge(width = dodge)
2: layer(data = data, mapping = mapping, stat = stat, geom = GeomPoint, 
       position = position, show.legend = show.legend, inherit.aes = inherit.aes, 
       params = list2(na.rm = na.rm, ...))
1: geom_point(aes(x = Outcome, y = Coefficient, color = Variable, 
       shape = Variable), show.legend = TRUE, size = 2.5, stroke = 1.2, 
       position = position_dodge(width = dodge))
sandra
  • 1
  • 1
    It looks like you forgot to assign a numeric value to your `dodge` object (for example `dodge <- 0.9`) before making your plot – rps1227 Aug 07 '23 at 09:00

0 Answers0