【问题标题】:How to set tick labels to edges of continuous ggplot2 legend如何将刻度标签设置为连续ggplot2图例的边缘
【发布时间】:2016-01-07 01:30:00
【问题描述】:

假设我有以下情节:

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))

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

【问题讨论】:

    标签: r ggplot2


    【解决方案1】:

    您可以指定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))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-11
      • 1970-01-01
      • 2020-11-20
      • 2019-10-29
      • 1970-01-01
      相关资源
      最近更新 更多