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

问题描述 投票:1回答:1

我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上。

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

r png legend
1个回答
0
投票

这对我有用:

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。

© www.soinside.com 2019 - 2024. All rights reserved.