我试图在我的图形标题中得到“不等于”的符号。unicode符号是U+2260。当我在下面的示例中运行main_title行时,符号将显示在控制台中。下面是示例代码:
#Example data
testy <- data.frame(Est = rnorm(10), method2 = paste0("Method", 1:10) )
#Title for plot
main_title <- expression(bold(paste("Sample selection (", psi[3], "\u2260 \u0021 0)")))
##Plotting
ggplot(data = testy, aes(x=method2, y = Est)) +
geom_point( ) +
geom_hline(yintercept = 0, color= "red", linetype = "dashed") +
theme(axis.text.x = element_text(angle = 45, hjust = 1),
legend.position = "none") +
xlab("") + ylab("") +
ggtitle(main_title) 当运行ggplot命令并显示图形时,“不等于”符号将转换回标题中的unicode号。我尝试为感叹号(U+0021)添加一个额外的unicode,以查看问题是否是unicode本身。感叹号unicode显示正确,但unicode不显示。
我尝试使用sprintf,并打印出来作为一个pdf,但“不等于”unicode号码显示在这两种情况下,而不是符号。如果有人对我出错的地方有任何建议,请告诉我。
发布于 2022-10-04 12:45:26
≠符号可以直接使用plotmath -只需在表达式中使用!=,它将以≠的形式出现。
ggplot(data = testy, aes(x=method2, y = Est)) +
geom_point( ) +
geom_hline(yintercept = 0, color= "red", linetype = "dashed") +
theme(axis.text.x = element_text(angle = 45, hjust = 1),
legend.position = "none") +
xlab("") + ylab("") +
ggtitle(expression(bold(Sample~selection~(psi[3] != 0))))

https://stackoverflow.com/questions/73947060
复制相似问题