如何在条形图的标题内使用右箭头? 我尝试了以下方法:
counts <- c(0.2, 0.4)
barplot(counts, main="A → B", horiz=TRUE, col=2:3, xlab="Time", xlim=c(0, 1.0))
在R中,情节的标题看起来不错但是当我将情节保存到文件时,例如pdf,标题中的右箭头替换为三个点&#39; ...&#39;。
我在Windows 7下使用R.
谢谢!
答案 0 :(得分:10)
我们可以使用expression()
:
set.seed(1)
d1 <- data.frame(y = rnorm(100), x = rnorm(100))
plot(y ~ x, data = d1,ylab = expression(y %->% x),xlab = expression(x %->% y))
表达式列表可在以下网址找到:https://stat.ethz.ch/R-manual/R-devel/library/grDevices/html/plotmath.html
答案 1 :(得分:2)
目前的答案是正确的,但我想我会添加一些提示,将其扩展到没有plotmath %...%
中缀运算符以及#34;特殊字符&#34;的情况。 ?plotmath
页面将我们引用到符号字体字符的points
页面,这是在那里定义的TestChars()
函数的修改版本,它具有选择所需的八进制(或可选的十进制)值系统上显示的一个字形:
TestCharsSym <- function(sign = 1, font = 5, oct = TRUE, ...)
{
MB <- l10n_info()$MBCS
r <- if(font == 5) {
sign <- 1
c(32:126, 160:254)
} else {
if(MB) 32:126 else 32:255
}
if (sign == -1) r <- c(32:126, 160:255)
par(pty = "s")
plot(c(-1, 16), c(-1, 16),
type = "n",
xlab = "",
ylab = "",
xaxs = "i",
yaxs = "i",
main = sprintf("sign = %d, font = %d", sign, font)
)
grid(17, 17, lty = 1)
mtext(paste("MBCS:", MB, " Use symbol(\"...\") "))
for(i in r){
try(points(i%%16, i%/%16, pch = sign*i, font = font, ...))
text(i%%16 - 0.3, i%/%16 - 0.3,
if( oct ){
paste0("\\", as.octmode(i))
} else{
i
},
cex = 0.5)
}
}
TestCharsSym()
我的系统是OSX,如果您正在查看我的交互式绘图设备中的240字形,但pdf()
设备不再使用Apple Symbol字体,则可以看到。要在*symbol(...)
的表达式中使用此信息,您需要&#34;编码&#34;八进制中的十进制值,并使用前面引用的反斜杠传递给plotmath()
函数。向前箭头可以用:
main=expression(A *symbol('\256')* B)