图例是页面(R)中错误位置的豌豆:未完全显示 [英] Legend is apears in the wrong place in the page (R): not fully shown

查看:172
本文介绍了图例是页面(R)中错误位置的豌豆:未完全显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have added the following command to the plot in 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)

但是,图例显示在图的外部,但没有完全显示出来,

However, the legend appears outside of the plot and not fully shown,

我希望它可以在情节的右侧之外看到.我不明白这里的位置

I want it to be seen outside right side of plot. I do not understand the positioning here

推荐答案

如果将title函数"topleft"更改为"topright"并删除inset自变量,则标题应为OK. 请参见下面的代码:

If you change in title function "topleft" to "topright" and remove inset argument you title should be indicated OK. Please see the code below:

# 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)

输出:

这篇关于图例是页面(R)中错误位置的豌豆:未完全显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆