@teunbrand was spot on.
Interesting. You may have somehow more or less voluntarily used I()
, which lets R interpret an object "as is". See also ?I
Here how to convert back to plain character:
You can do that either temporarily in the call to ggplot itself, or more permanently, by assignment (which I think you want to do).
update
in the comments, user teunbrand pointed to the S3 Method scale_type.AsIs
, which is why using an "asIs" object works just like using scale...identity
## this is to reproduce your data structure
iris2 <- iris
iris2$Species <- I(as.character(iris2$Species))
library(ggplot2)
ggplot(iris2, aes(x=Sepal.Length, y = Sepal.Width, color = Species)) +
geom_point()
#> Error: Unknown colour name: setosa
#convert withing ggplot
ggplot(iris2, aes(x=Sepal.Length, y = Sepal.Width, color = as.character(Species))) +
geom_point()

## convert by assignment
iris2$Species <- as.character(iris2$Species)
ggplot(iris2, aes(x=Sepal.Length, y = Sepal.Width, color = Species)) +
geom_point()

Created on 2020-07-01 by the reprex package (v0.3.0)