如何在R中设置坐标轴?

时间:2013-03-30 12:25:21

标签: r

我使用以下代码获得了graph1.jpg,

x = seq(-0.25, 1.25, length = 400)
y1=x
plot(x, y1,type="l",ann=FALSE)
text(0.3,0.2,labels="y=x")
mtext("x", 1, at=1.25, line=1)
mtext("y", 2, at=1.25, line=1)

请比较graph1.jpg和graph2.jpg,它们之间有两个主要差异,如何将graph1更改为graph2?

1.将graph1中的坐标轴更改为graph2。如何设置坐标的原点 2.图1中坐标轴的箭头没有 3.使y(graph1.jpg中y轴的mtext)水平

这是graph1.jpg。  enter image description here

这是graph2.jpg,也许graph2.jpg是由gimp制作的。 enter image description here

1 个答案:

答案 0 :(得分:0)

使用arrowsaxis并设置一些plot参数即可获得此信息:

enter image description here

## you call plot without axes, without box, without axes labels
plot(x, y1,type="l",frame.plot=FALSE,
     axes=FALSE,xlab='',ylab='')
## write some text
text(0.3,0.2,labels="y=x")
text(max(x),-0.1,"x")
text(-0.1,max(x),'y')
## draw axes lines with arrows
arrows(min(x), 0, max(x), 0)
arrows(0, min(x), 0, max(x))
## add axes ticks
axis(1,at=c(0,0.5,1),pos=0)
axis(2,at=c(0,0.5,1),pos=0)