Ggplot conflict between bay and scale_fill_discrete / story legend

I was messing around with geom_point trying to build the following code. I converted $ vs cars to a factor with discrete levels so that I could visualize both levels of this variable in different colors, assigning it to “fill” in the ggplot aes settings.

cars <- mtcars
cars$vs <- as.factor(cars$vs)

ggplot(cars,aes(x = mpg, y = disp, fill = vs)) +
  geom_point(size = 4) +
  scale_fill_discrete(name = "Test")

The result is this:

As you can see, the graph does not distinguish between fill conditions through color. However, it retains the legend label specified in scale_fill_discrete.

Alternatively, I can build the following (same code, but use “color” instead of “fill”)

cars <- mtcars
cars$vs <- as.factor(cars$vs)

ggplot(cars,aes(x = mpg, y = disp, color = vs)) +
  geom_point(size = 4) +
  scale_fill_discrete(name = "Test")

enter image description here

, "color" "fill" , , , , , scale_fill_discrete.

"fill" ? vis scale_fill_discrete?

+4
2

color , scale_color_* scale_fill_*:

ggplot(cars,aes(x = mpg, y = disp, color = vs)) +
      geom_point(size = 4) +
      scale_color_discrete(name = "Test") 

enter image description here

+4

fill geom_point, :

ggplot(cars,aes(x = mpg, y = disp, fill = vs)) +
  geom_point(size = 4, shape = 21) +
  scale_fill_discrete(name = "Test")

. ?pch, , 21 25 . ggplot fill, . , NEWS.

fill geom_point, , , , color, , .

+2

Source: https://habr.com/ru/post/1669095/


All Articles