更改图例项 ggplot

Changing Legend Items ggplot

我正在尝试创建图表,但无法更改图例项的名称。我的数据库是西班牙语的,我需要图例项目以英语显示。 Legend Items。我需要“70+”而不是“70 o más”。我已经尝试更改数据库中的值标签,但它也不起作用。

这是尝试更改数据库中的值标签的代码

library(expss)

describe(Flow)


Flow = apply_labels(Flow,
                      mes = "Month",
                      ano= "Year", 
                      edad="Age", 
                    edad=c("70 or more" = "70 o Más S/E"), 

这是图表的代码:

    chart<-ggplot()+
  geom_line(data=Flow %>%
            aes(x=date,
                color=edad), stat="count") +
  scale_x_date(date_minor_breaks = "1 month",
               date_labels = "%Y (%b)") +
  labs(color="Age")+
ggtitle("Number of Entrances, 2017-2021") 
ggplotly(chart)

如有任何帮助,我将不胜感激!

您可以使用scale_colour_gradient设置breaks,然后更改labels

library(tidyverse)

ggplot() +
  geom_line(data=mtcars,
              aes(x=cyl, y = mpg,
                  color=mpg)) +
  scale_colour_gradient(breaks = c(15, 20, 25, 30, 40),
                        labels = c("1+", "2+", "3+", "4+", "5+"))

输出