2016-01-06 135 views
3

比方說,我有以下情節:如何刻度標記設置爲連續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)?我希望讀者知道傳說的限制是什麼,不必猜測。

回答

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