在 R 图中使用 latex2exp 切断图例文本
Legend text cuts off using latex2exp in R plot
我的图例中的文字被图例中的 library(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)
有没有办法纠正这个问题?
我不确定问题出在哪里,但我根本无法解析您的乳胶字符串。不管怎样,如果你直接把它们写成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)
我的图例中的文字被图例中的 library(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)
有没有办法纠正这个问题?
我不确定问题出在哪里,但我根本无法解析您的乳胶字符串。不管怎样,如果你直接把它们写成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)