在R中设置图形图例的大小

set the size of figure legend in R

各位。我在 R studio 中使用 plot 函数。下面是我的情节。如您所见,图形图例框太大,我想将其设置得小一些。我试图修改相同的参数,但没有用。 我的代码是:

legend("topleft", legend=names(attr(colcode, "table")), 
       fill=attr(colcode, "palette"), cex=0.6,bg = "white", text.width = 1)

您指定的 text.width = 1 在您的图表上是图表的整个宽度。如果你减少 text.width,它看起来就可以了。尝试

legend("topleft", legend=names(attr(colcode, "table")), 
       fill=attr(colcode, "palette"), cex=0.6,bg = "white", text.width = 0.1)

您可能需要进一步减少它。