Giter Site home page Giter Site logo

Comments (3)

jacob-long avatar jacob-long commented on June 12, 2024

Hi! I've transferred this issue to the new interactions package, where this function has moved.

As for your questions, it is possible to accomplish this using ggplot2, which is the package this function relies on to create the plot. Many people who are new (and often not so new) to R run into issues with ggplot2, so don't feel bad. I made the package because I know it can be hard to learn all this stuff!

I'll use some example code to show how to accomplish this. First, the axis titles should be fairly simple, using the ggplot2 functions xlab() and ylab().

library(interactions)
library(ggplot2)
states <- as.data.frame(state.x77)
states$HSGrad <- states$`HS Grad`
fit <- lm(Income ~ HSGrad + Murder * Illiteracy, data = states)
object <- johnson_neyman(model = fit, pred = Murder, modx = Illiteracy)
# the plot is stored in object$plot
object$plot + xlab("My new x-axis title") + ylab("My new y-axis title")

Relabeling the points along the x-axis is a little more complex, but doable. It will require you to know the mean of the variable on the x-axis because we're going to add that number to the existing labels. For demonstration purposes, we'll say the mean is 5. We make a function that adds the mean to its input and then give that to ggplot2's scale_x_continuous() function to the labels argument, telling it to apply that function to all the values on the x-axis.

# Creating a function that will edit the labels
new_labeller <- function(x) x + 5 # adds 5 
# still using the object from earlier
object$plot + scale_x_continuous(labels = new_labeller)

Putting those pieces together, then...

library(interactions)
library(ggplot2)
states <- as.data.frame(state.x77)
states$HSGrad <- states$`HS Grad`
fit <- lm(Income ~ HSGrad + Murder * Illiteracy, data = states)
object <- johnson_neyman(model = fit, pred = Murder, modx = Illiteracy)
# Creating a function that will edit the labels
new_labeller <- function(x) x + 5 # adds 5 
# the plot is stored in object$plot
object$plot + xlab("My new x-axis title") + ylab("My new y-axis title") +
  scale_x_continuous(labels = new_labeller)

from interactions.

Mababyak avatar Mababyak commented on June 12, 2024

Thanks so much for this, Jacob! Been trying to figure this out for some time! Maybe you can include this info on the vignettes page?

Really appreciate the package!

from interactions.

zaslove avatar zaslove commented on June 12, 2024

Thanks! I too have been trying to figure this out. But this works!

from interactions.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.