2

I'm using plotreg() from the texreg package to display coefficient and CI estimates, but I find that I was not able to reproduce graphical output with layout similar to those done by others. For example, using the working example here:

# install.packages("texreg")
library(texreg)

# load example data
library(car)
prestige.dat <- data.frame(Prestige)

# standardizing the data
pres_mean <- mean(prestige.dat$prestige, na.rm = TRUE)
pres_sd <- sd(prestige.dat$prestige, na.rm = TRUE)
prestige.dat$prestige.std <- (prestige.dat$prestige - pres_mean) / pres_sd
                                
inc_mean <- mean(prestige.dat$income, na.rm = TRUE)
inc_sd <- sd(prestige.dat$income, na.rm = TRUE)
prestige.dat$income.std <- (prestige.dat$income - inc_mean) / inc_sd
                            
educ_mean <- mean(prestige.dat$education, na.rm = TRUE)
educ_sd <- sd(prestige.dat$education, na.rm = TRUE)
prestige.dat$education.std <- (prestige.dat$education - educ_mean) / educ_sd

# standardized regression
mod.std <- lm(prestige.std ~ income.std + education.std, data = prestige.dat)

# plot
plotreg(list(mod.std),
          custom.coef.names = c("Intercept", "Income", "Education"),
          custom.model.names = c("Model"),
          reorder.coef = c(2, 3, 1),
          lwd.vbars = 0)

Supposedly, I should produce something like this

enter image description here

But I got this instead enter image description here

I'm wondering if there's a way to remove the outer frame of my plotreg output and put the title (Model) on top of the graph (instead of having it placed vertically on the left y-axis of the graph)?

Or it could be that the authors of the package have dramatically changed the default setting, so that the layout used in the working example is no longer available.

#UPDATE

Following @IRTFM's recommendation (changing the plotting theme()), I was able to make the graphical output look much similar to the working example. So that the frame is removed and the main title now sits on top of the graph, only that I still could not set the 0-reference vertical bar to solid line (I have tried using the [ref.line.par][4] argument in coefplot(), but it didn't work)

I used the following code:

plt <- plotreg(list(mod.std),
          custom.coef.names = c("Intercept", "Income", "Education"),
          custom.model.names = c("Model"),
          reorder.coef = c(2, 3, 1),
          lwd.vbars = 0)

library(ggplot2)
plt + ggtitle("Model") + 
      theme(panel.border=element_blank(),               strip.text=element_text(size=12, colour="transparent"), strip.background=element_rect(colour="transparent", fill="transparent"), plot.title = element_text(hjust = 0.5))

The output looks like this

enter image description here

Chris T.
  • 1,699
  • 7
  • 23
  • 45
  • Can you find a dataset that exhibit the same sort of results or can you post sufficient data to allow work on the problem? – IRTFM Dec 08 '21 at 04:45
  • @IRTFM I follow the board's rule by posing minimal example and I simply replicate the code listed on that web-based manual, using the same data, but just could not reproduce the author's graphical result. I mean the code works but it just couldn't produce the same layout. – Chris T. Dec 08 '21 at 04:52
  • Oh. Sorry. I didn’t realize Prestige was a dataset in a package that was loaded. Who were these “others”? – IRTFM Dec 08 '21 at 04:54

1 Answers1

2

It looks like a lattice plot to me. There are three major plotting paradigms: base, lattice and ggplot. If you execute:

plt <- plotreg(  list(mod.std),
     custom.coef.names = c("Intercept", "Income", "Education"),
     custom.model.names = c(""),
     reorder.coef = c(2, 3, 1),
     lwd.vbars = 0)

str(plt)

... you see at the very end of the result

 # much above
 attr(*, "class")= chr [1:2] "gg" "ggplot"

So I'm wrong. It's a ggplot, so you need to look at the theme settings and figure out how to a) get rid of the box and grid, b)round the CI bars, and c) get rid of the y-oriented "Model" band AKA "facet" label.

Searching:

a) https://stackoverflow.com/questions/10861773/remove-grid-background-color-and-top-and-right-borders-from-ggplot2?r=SearchResults&s=1|84.3914

b) change $ lineend : chr "butt"` # to round (Not working)

$ theme      :List of 93
..$ line                      :List of 6
.. ..$ colour       : chr "black"
.. ..$ size         : num 0.5
.. ..$ linetype     : num 1
.. ..$ lineend      : chr "butt"

c) get rid of facet label:

plt +theme(panel.border=element_blank(),
           strip.text=element_text(size=12, colour="transparent"),
           strip.background=element_rect(colour="transparent", 
                                         fill="transparent"))

So I've hacked most of it and can get this far:

enter image description here

IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • Many thanks for your suggestion, I was able to make the output look like the one I wanted to the extent possible (see my update on the original post), only that I am still unable to change the 0-referenced vertical line to solid line. – Chris T. Dec 08 '21 at 16:07