x<-seq(-3,3,by=0.1)
y=0.5*x^3
png( "~/myplot.png" , width = 600 , height = 2600 ,units="px",res=100)
par( pin = c(6,26) )
par( mai = c(0,0,0,0) )
par( omi = c(0,0,0,0) )
par( xaxp = c(-3,3,7) )
par( yaxp = c(-13,13,27) )
plot( x , y , type = "l" , frame.plot = FALSE , axes = FALSE )
axis( 1 , pos = 0 , at = seq( -3 , 3 , by = 1 ) , labels = seq( -3 , 3 , by = 1 ) )
axis( 2 , pos = 0 , at = seq( -13 , 13 , by = 1 ) , labels = seq( -13 , 13 , by = 1 ) )
text(0.5,5,expression(f(x)==frac(1,2)*x^3) )
dev.off()
我们可以获得一个宽度为6英寸,高度为26英寸的图形,但是x轴或y轴上的刻度单位不是1英寸;请查看附件g1.png。原因是R不会使用整个空间来设置x轴和y轴,而是保留一点空间,请查看附件g2.png。我可以使用
png("~/myplot.png", width=610, height=2700, units="px", res=100)
,但如何使刻度单位的物理长度恰好为1英寸?