如何设置刻度标签到连续ggplot2图例的边缘

时间:2016-01-06 17:13:29

标签: r ggplot2

我们说我有以下情节:

library(ggplot2)
d = subset(diamonds, price >= 257 & price <= 8888)

ggplot(d, aes(depth, carat, colour = price)) +
  geom_point() +
  scale_colour_gradient(limits = c(257, 8888))

plot

如何更改图例以使刻度线标签显示最小值和最大值(257和8888)?我希望读者知道传说中的限制是什么,而不必猜测。

1 个答案:

答案 0 :(得分:4)

您可以指定breakslabels

ggplot(d, aes(depth, carat, colour = price)) +
  geom_point() +
  scale_colour_gradient(limits = c(257, 8888), 
                        breaks = c(257, 2000, 4000, 6000, 8000, 8888),
                        labels = c(257, 2000, 4000, 6000, 8000, 8888))

enter image description here