图例文本在r图中使用latex2exp切断

发布于 2025-01-20 06:08:05 字数 892 浏览 7 评论 0原文

我的传说中的文字使用库(latex2exp)在传说中切断。

library(stats)
library(evd)
library(dgumbel)
library(latex2exp)

x=seq(-5,10,length.out=1001)

fgumb=dgumbel(x,location=0,scale=1)
ffrech=dfrechet(x,loc=0,scale=1,shape=1)
fweib=dweibull(x,shape=2,scale=1)

maxes=max(fgumb,ffrech,fweib)

plot(x,fgumb,type='l',lwd=2,col='blue',ylim=c(0,maxes),
     ylab="f(x)")

lines(x,ffrech,type='l',lwd=2,col='red')
lines(x,fweib,type='l',lwd=2,col='green')

legend("topright",
       legend=c(TeX(r'(Gumbel(\mu=0,\sigma=1)'),
                TeX(r'(Frechet(\mu=0,\sigma=1,\xi=1)'),
                TeX(r'(Weibull(\sigma=1,\xi=2)')),
       col=c("blue","red","green"),
       lwd=c(2,2,2),cex=1)

有没有办法对此进行纠正?

The text in my legend cuts off using library(latex2exp) in a legend.

library(stats)
library(evd)
library(dgumbel)
library(latex2exp)

x=seq(-5,10,length.out=1001)

fgumb=dgumbel(x,location=0,scale=1)
ffrech=dfrechet(x,loc=0,scale=1,shape=1)
fweib=dweibull(x,shape=2,scale=1)

maxes=max(fgumb,ffrech,fweib)

plot(x,fgumb,type='l',lwd=2,col='blue',ylim=c(0,maxes),
     ylab="f(x)")

lines(x,ffrech,type='l',lwd=2,col='red')
lines(x,fweib,type='l',lwd=2,col='green')

legend("topright",
       legend=c(TeX(r'(Gumbel(\mu=0,\sigma=1)'),
                TeX(r'(Frechet(\mu=0,\sigma=1,\xi=1)'),
                TeX(r'(Weibull(\sigma=1,\xi=2)')),
       col=c("blue","red","green"),
       lwd=c(2,2,2),cex=1)

enter image description here

Is there a way to correct this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

于我来说 2025-01-27 06:08:05

我不确定问题是什么,但我根本无法解析你的乳胶字符串。无论如何,如果您直接将它们编写为 R 表达式,您的问题就可以解决:

plot(x,fgumb, type = 'l' ,lwd = 2, col = 'blue', ylim = c(0, maxes), ylab = "f(x)")

lines(x, ffrech, type = 'l', lwd = 2, col = 'red')
lines(x, fweib, type = 'l', lwd = 2, col = 'green')

legend("topright",
       legend = c(expression(paste('Gumbel(', mu==0~','~sigma==1, ')')),
                  expression(paste('Frechet(', mu==0~','~sigma==1, ',', xi==1, ')')),
                  expression(paste('Weibull(', sigma==1~','~xi==2, ')'))),
       col = c("blue", "red", "green"),
       lwd = c(2, 2, 2), cex = 1)

在此处输入图像描述

I'm not sure what the problem is, but I couldn't get your latex strings to parse at all. In any case, if you write them directly as R expressions, your problem resolves:

plot(x,fgumb, type = 'l' ,lwd = 2, col = 'blue', ylim = c(0, maxes), ylab = "f(x)")

lines(x, ffrech, type = 'l', lwd = 2, col = 'red')
lines(x, fweib, type = 'l', lwd = 2, col = 'green')

legend("topright",
       legend = c(expression(paste('Gumbel(', mu==0~','~sigma==1, ')')),
                  expression(paste('Frechet(', mu==0~','~sigma==1, ',', xi==1, ')')),
                  expression(paste('Weibull(', sigma==1~','~xi==2, ')'))),
       col = c("blue", "red", "green"),
       lwd = c(2, 2, 2), cex = 1)

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文