在 R 中创建 PNG 时,图例被截断

When creating PNG in R, the legend is cut off

我 4 年前写了一些 R 代码,此后就没有使用过 R。我正在努力让它再次工作:

radio_count = data[c("a","ac","an","bn","g")]

# Create a new PNG file
png(filename=png_file, width=850, height=600, bg="white") #,antialias="cleartype")

# Expand right side of clipping rect to make room for the legend
par(xpd=T, mar=par()$mar+c(5,0,0,5),las=3)

# actually plot the bar graphs, with title
barplot( t(radio_count), main=gr_title, ylab="# of clients",col=barcolors,names.arg=data[,1],ylim=c(0,150) )

legend(36.5,100,chartlegend,cex=0.8,fill=barcolors)
grid(nx= 0, ny = NULL, col="gray60",equilogs = TRUE) 

dev.off()

在 850x600 的情况下,图例被略微剪掉了 - 这意味着它只显示了图例的大约 80%,最右边的部分被截掉了。

我现在需要使用 1920x1080,图例根本不在 PNG 上。

我需要调整什么才能在屏幕上显示图例?

这对我有用:

barplot( t(radio_count), main=gr_title, ylab="# of clients", col=barcolors,
             cex.main=2.2, cex.names=1.65, cex.axis=1.65, cex.lab=1.4, 
             names.arg=data[,1], ylim=c(0,150) )

另请注意,ylim=c(0,150) 告诉 R 使 Y 轴的范围从 0 到 150。