我想绘制一张x轴和y轴的开头为0的图片,但是在我的代码下,结果无法满足我的要求。所以我想知道错误在哪里。谢谢!
rm(list=ls())
axis.test<-function(){
t<-seq(0,200)
ntbase<-12/(1+exp(-(t-10)/25))
nt1<-12/(1+exp(-(t-30)/25))
nt2<-15.5334/(1+exp(-(t-20)/25))
nt3<-10.6997/(1+exp(-(t-5)/25))
nt4<-13.5906/(1+exp(-(t-30)/50))
nt<-data.frame(cbind(ntbase,nt1,nt2,nt3,nt4)) matplot(t,nt,col=1:5,type='l',lwd=2,lty=1:5,ylab="population(100,000)",xaxs='i',yaxs='i',xaxt='n',yaxt='n')
axis(side=1,at=c(0,20,40,60,80,100,120,140,160,180,200),labels=c(0,20,40,60,80,100,120,140,160,180,200),tck=0.03)
axis(side=2,at=c(0,5,10,15,20),labels=c(0,5,10,15,20),tck=0.03)
}
axis.test()
答案 0 :(得分:0)
通过“绘制图片”,我假设您的意思是绘制图形。附带说明:我建议使用缩进和空格以提高代码的可读性。看看Hadley's Advanced R Style guide可以改善您的R编码风格。
您可以通过matplot
自变量xlim
和ylim
来指定轴限制
matplot(
t, nt,
col=1:5,
type='l',
lwd=2,
lty=1:5,
ylab="population(100,000)",
xaxs='i', yaxs='i',
xaxt='n', yaxt='n',
xlim = c(0, 200),
ylim = c(0, 20))
axis(
side=1,
at=seq(0,200,20),
labels=seq(0,200,20),
tck=0.03)
axis(
side=2,
at=seq(0,20, 5),
labels=seq(0,20,5),
tck=0.03)