Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R绘图:图例背景大小_R_Plot_Legend_Scatter Plot - Fatal编程技术网

R绘图:图例背景大小

R绘图:图例背景大小,r,plot,legend,scatter-plot,R,Plot,Legend,Scatter Plot,我正在使用R绘制一个图(特别是散点图),并注意到图例的背景尺寸过大(如下所示): 有什么办法可以缩小面积吗 我试图更改cex,但它不仅缩小了面积,而且缩小了字体大小。我想保持字体大小,但缩小图例区域 为了以防万一,我附上了我使用的图例代码: legend(x="bottomleft", legend = c("Survived (0)", "Died (1)"), col=c(1:length(levels(Noa

我正在使用R绘制一个图(特别是散点图),并注意到图例的背景尺寸过大(如下所示):

有什么办法可以缩小面积吗

我试图更改cex,但它不仅缩小了面积,而且缩小了字体大小。我想保持字体大小,但缩小图例区域

为了以防万一,我附上了我使用的图例代码:

legend(x="bottomleft", legend = c("Survived (0)", "Died (1)"), 
         col=c(1:length(levels(Noadr.for.plot2$Death))), pch = c(19, 17),
         y.intersp = 0.4,
         bg = "gray")
[更新] 这里是修改后的图。我可以修改文本宽度,但不能修改高度(如下所示):
您可以执行以下操作:

attach(mtcars)
plot(wt, mpg, main="Scatterplot Example",
     xlab="Car Weight ", ylab="Miles Per Gallon ", pch=19)
# op <- par(cex = 1)

text = c("Survived (0)", "Died (1)")
cex_val = 1

legend(x="bottomleft", legend = text,
       pch = c(19, 17), cex=cex_val,
       y.intersp = 1,
       bg = "gray",
       text.width = strwidth(text)[1]*cex_val)
附加(mtcars)
绘图(wt、mpg、main=“散点图示例”,
xlab=“汽车重量”,ylab=“每加仑英里数”,pch=19)

#op@@David S嗨,David!谢谢你的评论。我成功地工作了!但是,我可以修改文本宽度,而不是高度。请看上图(我上传了更新后的图)。我假设会有一个类似text.height的函数,但不幸的是它不存在。。。