-2

I'm trying to visualize a single scatterplot using ggplot2 and adjust the colors to make the graph more visually appealing, however, the colors and fill functions are not populating the colors I want.

For reference I've looked through this very helpful link in addition to the tidyverse cheatsheets for ggplot2, neither of which cover how to change the color of one single variable.

See below dummy data set with chart example below showing desired colors as the variable names:

dfRaw<- as.data.frame(cbind(var1= rnorm(10,11,3), var2= rnorm(10,12,2)))

rawPlot<- ggplot(dfRaw, aes(x= var1, y= var2, fill= 'skyblue', color= 'skyblue')) + geom_point()
> rawPlot

scatterplot showing var1 vs. var2 with wrong colors

In the above, skyblue is being desginated as the fill and color but is neither. This happens whether I use one or both designations. I'm looking for advice on how to fix this in addition to directions to a color list for ggplot2.

dre
  • 474
  • 5
  • 19
  • 2
    `fill` in combination with `geom_point` only makes a difference if `shape` is a number between `21` and `25`. Take a look at `ggplot(data = data.frame(x = 1:25, y = 1:25)) + geom_point(aes(x, y, shape = y), fill = "skyblue", size = 2) + scale_shape_identity()` – markus Dec 27 '18 at 19:10

1 Answers1

3

The aes defines variables that map to different colours and fills and not colours and fills directly. Supplying the colour directly in geom_point (or outside aes) works:

rawPlot <- ggplot(dfRaw, aes(x=var1, y=var2)) +
   geom_point(colour='skyblue', fill='skyblue')
rawPlot

enter image description here

Anders Ellern Bilgrau
  • 9,928
  • 1
  • 30
  • 37