轴标签中的数学表达式 [英] Mathematical expression in axis label

查看:150
本文介绍了轴标签中的数学表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在R中,我使用expression(theta[l]),以使绘图轴的标签与LaTeX中的$\theta_l$相同.出于审美原因,我想显示$\theta_\ell$.你能帮我吗?

In R, I use expression(theta[l]) so that the label of my plot axis is that same as $\theta_l$ from LaTeX. For esthetic reasons, I'd rather like to display $\theta_\ell$. Can you help me?

编辑

之前,我做了

plot(1:10, 1:10, xlab=expression(theta[l]))

,然后将生成的图片导出为pdf.然后,使用

and I exported the resulting picture in pdf. Then, using

\begin{figure}[htbp]
\centerline{\includegraphics[scale=.6]{test.pdf}}
\end{figure}

我的图片插入了LaTeX.

my picture was inserted in LaTeX.

在评论之后,这是我现在要做的:

Following the comments, here is what I now do:

require(tikzDevice)
tikz("test.tex", standAlone=TRUE, width=5, height=5)

plot(1:10, 1:10, xlab="$\\theta_\\ell$")

dev.off()
tools::texi2pdf('test.tex')
system(paste(getOption('pdfviewer'),'test.pdf'))

但是,当我在LaTeX中插入转折图时,图形的质量不如以前.我还能做些什么吗?

However, when I insert the resuling plot in LaTeX, the quality of the figure is not as good as before. Is there something more that I can do?

推荐答案

确实没有理由使用

There is really no reason to use a possibly unmaintained package like 'tikzDevice' for such a simple problem. Part of the problem with the 'tikz' device is that it doesn't seem to correctly accept the 'xpinch' and 'ypinch' arguments that specify your plot's resolution.

还有一个更大的问题,就是在图上添加LaTEX表示法,但是对于这个局部问题,问题是指定字体以使基本"plotmath"程序包为您显示草书字母.

There is a larger question of adding LaTEX notation to plots, but for this localized problem, the question is one of specifying the font to make the base 'plotmath' package display cursive letters for you.

您可以更改x轴标签的字体,方法是将其与plot命令分开,然后从"title"功能中选择一种自定义字体,如下所示:

You can change the font for your x-axis label by separating it out from the plot command and choosing a custom font from within the 'title' function with something like this:

plot(1:10, 1:10, xlab="")
windowsFonts(script=windowsFont("Script MT Bold"))
title(xlab=expression(theta[l]), family="script")

我们要做的是在plot命令中为x轴指定一个空标签,以便首先腾出空间.然后,我们将系统字体加载到可用的字体系列中(我喜欢Script MT Bold用于表达式).最后,我们可以使用标题"功能绘制x轴标签,并为该标签中的任何文本指定族.

What we've done is to specify a null label for the x-axis in the plot command to first make space. Then, we load up a system font into the available font families (I like Script MT Bold for expressions). Finally, we can use the 'title' function to plot the x-axis label and specify the family for any text in that label.

这样做,我们保留了绘图设备的所有原始功能,因此转换为PDF时,分辨率不应再降低.

By doing this, we preserve all of the original functionality of the plotting device, so you should no longer have a drop in resolution when converting to PDF.

现在,如果有人在'tikzDevice'软件包之外对LaTEX表示法问题有很好的解决方案,我很想听听它.我唯一知道做到这一点的唯一方法是翻转模型并使用'tikz'LaTEX包从LaTEX文件中手动绘制整个图形,或者使用'pixmap'R包在上面绘制我的表情的图像情节的顶部.两种感觉都不是完美的方法.

Now if anyone has a good solution to the LaTEX notation problem outside of the 'tikzDevice' package, I would love to hear about it. The only way I know to do this well is to flip the model and use the 'tikz' LaTEX package to draw the whole graphic manually from within the LaTEX file or to use the 'pixmap' R package to draw an image of my expression on top of the plot. Neither feels like a perfect approach.

这篇关于轴标签中的数学表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆