我已经在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)
但是,图例显示在图的外部,但没有完全显示,
答案 0 :(得分:0)
如果您将title
函数"topleft"
更改为"topright"
并删除了inset
自变量,则标题应为OK。
请参见下面的代码:
# 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)