9
ggmap(location) +
geom_density_2d(aes(long, lat), df) +
geom_point(aes(long, lat,**color = special**),alpha = 0.5,data = df) 

I can not see what is different when I change color to the fill, like:

ggmap(location) +
geom_density_2d(aes(long, lat), df) +
geom_point(aes(long, lat,**fill = special**),alpha = 0.5,data = df) 

what is the main difference between those two arguments?

LachlanO
  • 1,152
  • 8
  • 14
nevh
  • 101
  • 1
  • 5

2 Answers2

11

Generally, fill defines the colour with which a geom is filled, whereas colour defines the colour with which a geom is outlined (the shape's "stroke", to use Photoshop language).

Points generally only have a colour and no fill, because, y'know—they're just points. However, point shapes 21–25 that include both a colour and a fill. For example:

library(tidyverse)
df = data_frame(x = 1:5, y = x^2)
ggplot(df) +
  geom_point(
    aes(x, y, fill = x),
    shape = 21, size = 4, colour = 'red')

A ggplot with fill mapped to an aesthetic and colour fixed.

Here's an example with ggmap, where both fill and colour are set (but not mapped to aesthetics):

library("ggmap")

us = c(left = -125, bottom = 25.75, right = -67, top = 49)
map = get_stamenmap(us, zoom = 5, maptype = "toner-lite")
df2 = data_frame(
  x = c(-120, -110, -100, -90, -80),
  y = c(30, 35, 40, 45, 40))

ggmap(map) +
  geom_point(
    aes(x, y), data = df2,
    shape = 21, fill = 'blue', colour = 'red', size = 4)

A ggmap with fixed colour and stroke.

But unless you're using those special shapes, if you use a point, give it a colour, not a fill (because most points don't have one).

jimjamslam
  • 1,988
  • 1
  • 18
  • 32
  • You explained the differences between `fill` and `color`, but it's still not clear why OP is getting the same output on using either(see the code snippets in the question). Is it that for some shapes, both can be applied without any differences in output? – amsquareb Jan 01 '20 at 08:42
3

This can't be answered much better than done so here.

The only reason I haven't marked this as duplicate as you're asking a slightly different question. They were experiencing what they thought was a bug, you are experiencing what you think is a no change.

In summary, there are several shapes you can choose for geom_point and only some of them have a fill and colour argument.

In general fill changes the colour within shapes, and colour changes the outline.

LachlanO
  • 1,152
  • 8
  • 14