用任意文本替换ggplot中连续图例上的数字

Roh*_*han 4 r legend ggplot2

我有一个用 ggplot 制作的带有连续色标的图。是否可以用文本替换比例图例上的数字?

在此处输入图片说明

例如,这里没有 5、10、15、20,我只想在 20 所在的位置使用“高”,在 5 所在的位置使用“低”。

谢谢!

ste*_*fan 7

使用 mtcars 作为示例数据。只需设置中断和/或标签,如下所示:

library(ggplot2)

ggplot(mtcars, aes(cyl, mpg, color = hp)) +
  geom_point() +
  scale_color_continuous(breaks = c(100, 200, 300), labels = c("low", "med", "high"))
Run Code Online (Sandbox Code Playgroud)

reprex 包(v0.3.0)于 2020 年 3 月 14 日创建