ggplot2,在轴标签内的下标中获取 % 符号
ggplot2, getting a % symbol in subscript within axis labels
我正在尝试在轴中获取一个 % 符号作为下标。通常,使用表达式和方括号 []
可以获得下标。但是当我收到错误时,符号似乎无法正确解析。有谁知道如何修复或变通?比如下面的下标要%
怎么办:
library(tidyverse)
iris %>% ggplot(aes(x = Sepal.Length, y = Sepal.Width)) +
geom_point(aes(colour = Species)) +
geom_smooth(method = loess) +
labs(y = expression(Blah[1*d]*"%"))
当%
符号在括号中移动时
iris %>% ggplot(aes(x = Sepal.Length, y = Sepal.Width)) +
geom_point(aes(colour = Species)) +
geom_smooth(method = loess) +
labs(y = expression(Blah[1d%]))
出现以下错误消息:
Error: unexpected symbol in: " geom_smooth(method = loess) +
labs(y = expression(Blah[1d"
移动方括号中的 %
符号并使用引号""
删除错误消息
iris %>% ggplot(aes(x = Sepal.Length, y = Sepal.Width)) +
geom_point(aes(colour = Species)) +
geom_smooth(method = loess) +
labs(y = expression(Blah["1d%"]))
并生成此图:
我正在尝试在轴中获取一个 % 符号作为下标。通常,使用表达式和方括号 []
可以获得下标。但是当我收到错误时,符号似乎无法正确解析。有谁知道如何修复或变通?比如下面的下标要%
怎么办:
library(tidyverse)
iris %>% ggplot(aes(x = Sepal.Length, y = Sepal.Width)) +
geom_point(aes(colour = Species)) +
geom_smooth(method = loess) +
labs(y = expression(Blah[1*d]*"%"))
当%
符号在括号中移动时
iris %>% ggplot(aes(x = Sepal.Length, y = Sepal.Width)) +
geom_point(aes(colour = Species)) +
geom_smooth(method = loess) +
labs(y = expression(Blah[1d%]))
出现以下错误消息:
Error: unexpected symbol in: " geom_smooth(method = loess) +
labs(y = expression(Blah[1d"
移动方括号中的 %
符号并使用引号""
删除错误消息
iris %>% ggplot(aes(x = Sepal.Length, y = Sepal.Width)) +
geom_point(aes(colour = Species)) +
geom_smooth(method = loess) +
labs(y = expression(Blah["1d%"]))
并生成此图: