Coder Social home page Coder Social logo

Comments (2)

strengejacke avatar strengejacke commented on June 16, 2024

removing (parts of) the legend in ggplot2 is a pain... Any hints how to remove the legend for single-color plot with text labels are welcome.

library(ggeffects)
lm_fit <- lm(mpg ~ cyl * wt, data = mtcars)
lm_fit_predict <- ggpredict(lm_fit, terms = c("cyl", "wt"))
plot(lm_fit_predict, add.data = TRUE, label.data = TRUE)
#> Data points may overlap. Use the `jitter` argument to add some amount of
#>   random variation to the location of data points and avoid overplotting.
#> Warning: ggrepel: 6 unlabeled data points (too many overlaps). Consider
#> increasing max.overlaps

plot(lm_fit_predict, add.data = TRUE, label.data = FALSE)
#> Data points may overlap. Use the `jitter` argument to add some amount of
#>   random variation to the location of data points and avoid overplotting.

lm_fit <- lm(mpg ~ cyl + wt, data = mtcars)
lm_fit_predict <- ggpredict(lm_fit, terms = "cyl")
plot(lm_fit_predict, add.data = TRUE, label.data = TRUE)
#> Data points may overlap. Use the `jitter` argument to add some amount of
#>   random variation to the location of data points and avoid overplotting.
#> Warning: ggrepel: 6 unlabeled data points (too many overlaps). Consider
#> increasing max.overlaps

plot(lm_fit_predict, add.data = TRUE, label.data = FALSE)
#> Data points may overlap. Use the `jitter` argument to add some amount of
#>   random variation to the location of data points and avoid overplotting.

Created on 2023-07-16 with reprex v2.0.2

from ggeffects.

Deleetdk avatar Deleetdk commented on June 16, 2024

Generally, avoid setting aes(color = x) if you don't have any groups to color. I usually do this by using an if clause, with two variants of geom_point() and geom_smooth(). But you can also suppress the legend manually if you like. E.g. theme(legend.position="none") removes all legends.

from ggeffects.

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.