我正在尝试把稳定的氧同位素符号输入到ggplot中的轴文本(刻度标记标签)中。
示例数据
df <- data.frame(author = c("one", "two", "three"),
d18O = c("D", "D", "U"),
Mg = c("I", "D", "D"),
`Drip Rate` = c("U", "I", "I")) %>%
pivot_longer(-c(author)) 外部图解
df %>%
ggplot(aes(x = name, fill = value)) +
geom_bar(position = "fill", colour = "black", size = 0.1) +
facet_grid(author~., scales = "free")scales::parse_format将解析符号的第一部分(δ^18)
df2 <- df
df2[which(df2$name == "d18O"),]$name <- "delta^18"
df2 %>%
ggplot(aes(x = name, fill = value)) +
geom_bar(position = "fill", colour = "black", size = 0.1) +
facet_grid(author~., scales = "free") +
scale_x_discrete(labels = scales::parse_format())

但是,当我试图添加O(为了使它成为Error in parse(text = text[[i]]) : <text>:1:9: unexpected symbol 1: delta^18O ^ ^18O)时,我得到了错误的δ
任何帮助都很感激!
发布于 2022-05-23 06:25:27
您需要添加一个星号来转义上标:
df2[which(df2$name == "d18O"),]$name <- "delta^18*O"发布于 2022-05-23 06:33:34
如果O表示Omicron,则可以使用
df2[which(df2$name == "d18O"),]$name <- "delta^~18*Omicron"https://stackoverflow.com/questions/72343955
复制相似问题