我试图创建一个百分比堆积条形图。我为复制生成了一些示例数据:
#Create dummy data (class is table)
one=c(1,1,.9855,1,1,.9956,.9827,.9868,.988,.9701,1,1,1)
zero=1-one
comp=as.table(rbind(one,zero));comp
#Set wanted axis limits
yax=c(max(min(comp[1,])-.1,0),1);yax
下面是我使用ylim设置轴限制之前的结果图:
#Before setting limits looks fine
par(mar=c(5,6,4,5)) #resize margins
barplot(comp,col=c("#3399CC","#CC0033"),main="Proportion of Results",
yaxt="n",legend.text=TRUE,
args.legend=list(x="topright",inset=c(-0.15,.45)))
axis(2,at=pretty(comp),lab=paste0(pretty(comp)*100," %"),las=TRUE)
然后,当我加入ylim参数时,我的条会超过设置的限制。
#After setting limits it's messed up
par(mar=c(5,6,4,5)) #resize margins
barplot(comp,col=c("#3399CC","#CC0033"),main="Proportion of Results",
yaxt="n",ylim=yax,legend.text=TRUE,
args.legend=list(x="topright",inset=c(-0.15,.45)))
axis(2,at=pretty(yax),lab=paste0(pretty(yax)*100," %"),las=TRUE) #Show y-axis labels as percent
我想切断和查看只有部分的绘图根据我选择的限制。有人知道我做错了什么吗?