Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

relabel_predictors masks the dot_args function #74

Closed
ryanburge opened this issue Nov 6, 2017 · 3 comments
Closed

relabel_predictors masks the dot_args function #74

ryanburge opened this issue Nov 6, 2017 · 3 comments

Comments

@ryanburge
Copy link

@ryanburge ryanburge commented Nov 6, 2017

@fsolt
Copy link
Owner

@fsolt fsolt commented Mar 30, 2018

Thanks, Ryan, for pointing this out, and for the reprex. Sorry to take so long to really look at this.

Unfortunately, I don't see an elegant fix. When x is dwplot output, relabel_predictors() just calls dwplot() again on the plotted data (which can easily be recovered with x$data), but there's no way to get the dot_args back since one cannot recover a ggplot call from a ggplot object (which appears to still be true, despite the date on that question and Hadley's answer).1 One option would be to add a dot_args argument to relabel_predictors(), which I started to implement, but when I was writing up the help it just seemed too clunky: "If x is a plot generated by dwplot(), a list of arguments specifying changes to the appearance of the dots representing mean estimates. For supported arguments, see geom_pointrangeh" and, you know, don't specify them in your call to dwplot(). Sigh.

There is, otoh, what I think is a fairly straightforward workaround: call relabel_predictors() first and then call dwplot():

regplot <- read_csv("https://raw.githubusercontent.com/ryanburge/cces/master/regplot.csv")

regplot %>%
relabel_predictors(c(treated = "White",
                        age = "Age",
                        educ = "Education",
                        income = "Income",
                        male = "Male",
                        imp = "Importance of Religion",
                        pid = "Republican ID",
                        attend = "Church Attendance",
                        pray = "Frequency of Prayer")) %>%
dwplot(dot_args = list(size = 5))

rplot

I've added a note describing this workaround to the help for relabel_predictors.

1: I almost convinced myself into thinking I'd solved this via ggplot_build, because it worked on the reprex, but that only allows a size argument to be recovered--and not, say, shape--as far as I could tell.

@fsolt fsolt closed this in 62f1ef2 Mar 30, 2018
@ryanburge
Copy link
Author

@ryanburge ryanburge commented Mar 30, 2018

That's a terrific (and easy) solution. Thanks very much.

@fsolt
Copy link
Owner

@fsolt fsolt commented Apr 6, 2018

Actually, inspiration struck a couple of nights ago, and I think I have a much better solution now. Your original code should work fine with the current dev version:

screen shot 2018-04-06 at apr 6 1 49 28 pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.