Giter VIP home page Giter VIP logo

Comments (3)

thomasp85 avatar thomasp85 commented on June 25, 2024

As stated in the documentation, if the input to values is a named vector the names will be used to match the values to the levels of the scale. Since iris$Species doesn't contain any values matching the names of your vector they will all be set to na.value

from ggplot2.

teunbrand avatar teunbrand commented on June 25, 2024

In addition to Thomas' comments, the next version will warn you that there are no names/values in common. Not quite sure why it warns twice though.

colors_named_vector <- c(
  red = "red",
  blue = "blue",
  green = "green"
)

library(ggplot2)

ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width, color=Species)) +
  geom_point() +
  scale_color_manual(values=colors_named_vector)
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's colour values.
#> No shared levels found between `names(values)` of the manual scale and the
#> data's colour values.

Created on 2024-01-30 with reprex v2.1.0

from ggplot2.

thomasp85 avatar thomasp85 commented on June 25, 2024

Also, you are using %>% instead of + when adding the scale. This is a working version of your code

colors_named_vector <- c(
    setosa = "red",
    versicolor = "blue",
    virginica = "green"
)


library(ggplot2)

ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width, color=Species)) +
    geom_point() +
    scale_color_manual(values=colors_named_vector)

from ggplot2.

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.