ggplot: получить дискретную легенду с scale_fill_gradient - PullRequest
0 голосов
/ 06 июня 2018

Я пытаюсь воссоздать пример фигуры из 'R Graphics Cookbook' стр.87.

enter image description here

Я пытаюсь воссоздать сследующий код, но я не получаю результат:

library(ggplot2)
library(hexbin)

sp <- ggplot(diamonds, aes(x=carat, y=price))
sp + stat_binhex() +
  scale_fill_gradient(low="lightblue", high="red",
                      breaks=c(0, 250, 500, 1000, 2000, 4000, 6000),
                      limits=c(0, 6000)) 

, который дает

enter image description here

1 Ответ

0 голосов
/ 07 июня 2018

Проблема решена.Оказывается, мне пришлось добавить направляющий аргумент:

sp <- ggplot(diamonds, aes(x=carat, y=price))
    sp + stat_binhex() +
      scale_fill_gradient(low="lightblue", high="red",
                          breaks=c(0, 250, 500, 1000, 2000, 4000, 6000),
                          limits=c(0, 6000), guide = "legend") 
...