使用标准杆时图例框宽度不正确 [英] Legend box width not correct when using par

查看:79
本文介绍了使用标准杆时图例框宽度不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是我的图例太大了,我的代码是

I have the problem , that my legend is too large, my code:

par(mfrow=c(1,2))
hist(alvsloss,breaks = 100, freq=F,main="Histogramm,
 density curve (gaussian kernel) \n and fitted normal distribution of Allianz simple losses ",xlim=c(-0.15,0.15),xlab="loss",ylab="density",cex.axis=1.2,cex.lab=1.2)
lines(density(alvsloss), col="black", lwd=2)
curve(dnorm(x, mean = mean(alvsloss), sd = sd(alvsloss)), add=TRUE, col="black",lwd=2,lty="dotted")

legend(-0.155, 30, c("(Gaussian) Kernel density","fitted normal distribution"),lwd=2, cex=0.8, 
   col=c("black","black"), lty=1:2)


qqnorm(alvsloss,main="normal QQ Plot",cex.axis=1.2,cex.lab=1.2)
qqline(alvsloss)

这给出了以下图片:

问题是,左侧的图例太大,如何控制盒子的宽度?盒子太大了.

The problem is, that the legend on the left is too big, how can I control the width of the box? The box is way too large.

数据可在此处找到: http://uploadeasy.net/upload/ocafq.rar

推荐答案

图例右边的空白告诉我您手动扩大了绘图窗口.当涉及到手动调整大小时,图例无法很好地缩放.

The white space on the right of you legend tells me that you manually widened your plot window. Legends do not scale well when it comes to manual re-sizing.

解决方案是在绘制之前打开一个您需要的确切大小的图.在Windows中,这是通过windows(width=10, height=8)完成的.单位为英寸.现在,周围的框应与文本紧密结合.

The solution is opening a plot of the exact size you need before plotting. In Windows, this is done with windows(width=10, height=8). Units are in inches. The surrounding box should now be tighter with the text.

如果仍然不能令人满意,则应尝试:

If this is still not satisfactory, you should try:

  1. 减小图例cex=0.7
  2. 的字体大小
  3. 删除图例bty = "n"周围的框,然后使用\n 将您的图例分成几行
  4. 您可以使用"topleft"在左侧添加更多图例 而不是坐标
  1. Reducing the font size of the legend cex=0.7
  2. Removing the box around the legend bty = "n" and using \n to split your legend onto several lines
  3. You can put your legend even more on the left using "topleft" instead of coordinates

这就是我要怎么做:

legend("topleft", 
 legend=c("(Gaussian)\nKernel\ndensity","Fitted\nnormal\ndistribution\n"),
 bty = "n",lwd=2, cex=0.7, col=c("black","black"), lty=1:2)

这篇关于使用标准杆时图例框宽度不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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