Comments (3)
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.
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.
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)
- coord_radial() and coord_polar() are not connecting the start and end points anymore (v3.5.1) HOT 3
- Suggestion for Improved Error Message for `geom_area()` with Discrete X-Axis
- `geom_area()` provides unclear error message when discrete x-axis is used HOT 1
- labeller example that uses an optional argument
- `scale_*_continuous` fails to render breaks if axis is reversed HOT 4
- When x values contain 0, using coord_trans("sqrt") removes the axis line HOT 4
- {marquee} integration HOT 1
- Encapsulate or export `{wrap/grid}_as_facets_list()`.
- ggplotly does not work when adding scale_fill_binned HOT 1
- Superfluous guidance in "Creating a new theme" section of ggplot2 packages vignette? HOT 2
- ggplot2 ignores the user's input for transparency via NA's in scale_fill_manual() HOT 12
- `guide_colorsteps()` can't set the `position` HOT 1
- strip.placement = "outside" and strip.switch.pad.wrap don't work together perfectly for facet_wrap. HOT 2
- `orientation` for `geom_step()` HOT 1
- Internal function `find_x_overlaps()` has bug
- layer code with geom = "rug" no longer works as expected in Development version
- stat_density() error and bw.nrd() man file are in conflict on valid inputs HOT 2
- binned_scale() function missing after version 3.4.1? HOT 1
- scale_y_discrete() fails without data to plot HOT 1
- Version 3.5.1 breaks passing of theme elements for ggplot2 extension HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ggplot2.