【问题标题】:更改图例项 ggplot
【发布时间】:2022-01-07 10:52:21
【问题描述】:

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

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

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)

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

【问题讨论】:

  • 如果您提供一些数据,那么我可以用您的代码完善我的答案。你可以在这里编辑你的问题,然后粘贴dput(Flow)的结果。
  • 请澄清您的具体问题或提供其他详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。

标签: r ggplot2 legend legend-properties


【解决方案1】:

您可以使用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+"))

输出

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-27
    相关资源
    最近更新 更多