r - 将宏添加到刻面标签中的字母
问题描述
正如标题所说,我想在分面标签中添加一个宏。一个例子:
library(tidyverse)
# subset data
df2 <- diamonds %>%
sample_n(500)
# plot
ggplot(df2,aes(x = carat, y = price)) +
geom_point() +
facet_wrap(~cut)
现在我想在 Fair 的 a 上添加一个宏
# attempt to recode Fair to Fāir
df2 <- df2 %>%
mutate(cut2 = fct_recode(cut, "F\u0101ir" = "Fair"))
# doesn't work - produces exactly the same plot as above.
ggplot(df2,aes(x = carat, y = price)) +
geom_point() +
facet_wrap(~cut2)
任何提示将非常感谢。
解决方案
看起来这是一个问题,fct_recode
而不是ggplot2
. 这似乎工作得很好
df2 <- diamonds %>%
sample_n(500)
df2$cut2 <- df2$cut
levels(df2$cut2)[1] <- "F\u0101ir"
ggplot(df2,aes(x = carat, y = price)) +
geom_point() +
facet_wrap(~cut2)
实际上我猜它与 R 中的所有参数名称有关。看起来你不能使用 unicode 名称(至少在我测试的 4.0.5 中不能)
foo <- function(...) {
print(match.call())
}
foo("F\u0101ir" = 1)
# foo(Fair = 1)
foo(Fāir = 1)
# foo(Fair = 1)
似乎这些值只是转换为 ASCII
推荐阅读
- c# - C# 到 R - HTTP GET
- encryption - 如何使用 DRM 获取 MPEG Dash?
- python - Python问题加入二进制像Ojbects
- c++ - 为什么对引用的 const 引用会失去其 const 性?
- flutter - 飞镖中的固定长度整数
- spring-boot - 如何从 Camunda 中的 EnumFormType 重置值?
- c# - 从 PowerPoint 中提取图像并使用 VSTO 加载项 c# 添加到 Word
- firebase - Flutter:可以等待兄弟小部件完成构建吗?
- javascript - 有没有办法避免反应钩子中的依赖数组?
- matplotlib - 如何用 matplotlib 绘制一个填充的矩形棱柱