r - R:如何在 ggplot 字幕中将 2019-04-29 显示为 2019 年 5 月 29 日?
问题描述
我需要将最小日期值和最大日期值放入ggplot subtitle
.
我发现了一个类似的问题,但是对于轴标签,我需要将其应用于 subtitle 参数:
subtitle = paste0("Del ", vitocho_likes_min_date, " al ", vitocho_likes_max_date)
最小日期看起来像:
"2010-10-14" #Expect: "14 de octubre del 2010"
dput(vitocho_likes_min_date)
structure(14896, class = "Date")
最大日期如下所示:
"2019-04-29" #Expect: "29 de abril del 2019"
dput(vitocho_likes_max_date)
structure(18015, class = "Date")
这是我的 ggplot 图表:
vitocho_chart <- t_kids_faves %>%
filter(user == "VictorAndresGB") %>%
ggplot(aes(x = fct_reorder(screen_name, n), y = n)) +
geom_col(fill = "#494A4F") +
coord_flip() +
theme_tweets() +
labs(
x = "",
y = "",
title = "Cuentas de Twitter con más likes de Victor Andrés García Belaunde.",
subtitle = paste0("Del ", vitocho_likes_min_date, " al ", vitocho_likes_max_date)
) +
geom_text(
aes(x = screen_name,
y = n - 15,
label = n
),
size = 4,
color = "gray95"
)
解决方案
利用:
Sys.setlocale("LC_TIME", "Spanish")
vitocho_likes_min_date= as.character(format(as.Date(14896, origin="1970-01-01"), "%d de %B del %Y"))
vitocho_likes_max_date= as.character(format(as.Date(18015, origin="1970-01-01"), "%d de %B del %Y"))
推荐阅读
- c - C语言中的字节顺序和移位运算符,我做对了吗?
- python - 设置 python 时无法使用特定的 gcc 版本
- c# - 将 NULL 值从数据库映射到对象的属性
- reactjs - 下一个 js 获取在 componentdidmount 上失败
- elasticsearch - 在弹性搜索过滤器中实现 Array.Except(Array2) > 0 查询?
- python - numpy 中的条件。如何使用 pandas 或 numpy 将 3 个或更多放入我的数据框中?
- xamarin - 如何更改 Xamarin Forms 中导航栏标题区域的字体大小?
- json - 仅在 JSON 之后加载 tableView
- uml - UML 状态图中是否允许没有直接转换的状态?
- android - 未找到 Azure Jenkins Android SDK