Reputation: 35
I am trying to assign a single color for all points on a scatter plot in ggplot2. However, no matter what color I set fill =
to, the points always end up being black.
Here is my code (with dummy variables):
ggplot(data = testDF) +
geom_point(aes(x = testDF$X, y = testDF$Y),
fill = "#2EC4B6", color = "#E71D36") # Fill is cyan, color is red
This is what the plot looks like:
https://i.sstatic.net/4nRHo.png
Upvotes: 2
Views: 2262
Reputation: 3788
You need to set the dot style with pch=21
. Default dot style does not use fill.
EDIT actual example:
ggplot(data = testDF) +
geom_point(aes(x = X, y = Y), # testDF has columns X and Y
fill = "#2EC4B6", color = "#E71D36", # Fill is cyan, color is red
pch = 21) # point style that uses both color and fill
As @Artem pointed out, you can also use the shape
aesthetic to change the dot style. I don't know exactly what the difference between pch
and shape
is, but I think pch
is from older versions of ggplot2
.
Upvotes: 4
Reputation: 13731
The default shape used by geom_point
does not have a fill
aesthetic. You can address this by changing the shape
parameter:
ggplot( mtcars, aes( x = wt, y = mpg ) ) +
geom_point( shape = 21, fill = "#2EC4B6", color = "#E71D36" )
Upvotes: 4