繁体   English   中英

图例出现在页面中错误的位置 (R):未完全显示

[英]Legend is apears in the wrong place in the page (R): not fully shown

我已将以下命令添加到 R 中的绘图中:

df<- read.table("filename.csv", header=TRUE, sep=",", stringsAsFactors=FALSE)
tdf=as.data.frame(df[2:ncol(df)])

# draw the plot
bb<- barplot(as.matrix(tdf), beside=T ,
             col=colours,border="black", ylim=c(0,100), ylab="Percentage (%)",xlab="Methods)")

y<-as.matrix(tdf)
text(bb,y+2,labels=as.character(y),pos =1,offset=3,cex = 0.6, col = "black") 



legend("topleft", c("M1","M2","M3","M4","M5", "M6"), cex=0.6,inset=c(1,0),xpd=TRUE,  fill=colours)

然而,图例出现在情节之外并没有完全显示,

我希望它在情节的右侧之外被看到。 我不明白这里的定位在此处输入图片说明

如果您在更改title功能"topleft""topright"和删除inset的说法,你的标题应该是指示确定。 请看下面的代码:

# simulation
set.seed(123)
tdf <- as.data.frame(matrix(rbinom(20, 15, .4) * 8, ncol = 4))

# draw the plot
colours <- 2:6
bb <- barplot(as.matrix(tdf), beside=T ,
             col=colours,border="black", ylim=c(0,100), ylab="Percentage (%)",xlab="Methods)")

y <- as.matrix(tdf)
text(bb,y+2,labels=as.character(y),pos =1,offset=3,cex = 0.6, col = "black") 
legend("topright", c("M1","M2","M3","M4","M5", "M6"), cex=0.6,xpd=TRUE,  fill=colours)

输出: 输出

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM