Reputation: 5553
I have a data set like the following one:
data<-data.frame(x=c(50,100,250,400),y1=c(0.74,0.75,0.82,0.79),y2=c(0.81,0.83,0.87,0.88))
I generate the plot like this:
plot(data$x,data$y1,type='l',col="red",xaxs='i',yaxs='i',ylim=c(0.4,1),xlim=c(50,500))
lines(data$x, data$y2, type='l',col="blue")
The generated figure is:
How could I make the following modifications on this plot?
1) The current X axis starts with 50. But it does not mark 50 explicitly.
2) The current X axis is marked as 100, 200, 300, 400, 500
, Can I mark it as 50,100, 250,500
?
3) The current Y axis is marked as 0.5, 0.6,0.7.0.8,0.9,1.0
. Can I mark it as 0.5, 0.55, 0.6, 0.65, 0.7,0.75, 0.8, 0.85, 0.9, 0.95, 1
?
4) I would like to add some grid line parallel to X axis. These lines should start at points of 0.5, 0.55, 0.6, 0.65, 0.7,0.75, 0.8, 0.85, 0.9, 0.95, 1
along the Y-axis.
Upvotes: 0
Views: 1021
Reputation: 4928
data<-data.frame(x=c(50,100,250,400),y1=c(0.74,0.75,0.82,0.79),y2=c(0.81,0.83,0.87,0.88))
windows()
plot(data$x,data$y1,type="l",col="red", ylim=c(0.5,1),xlim= c(50,500),col.axis = "white")
axis(1, xaxp=c(50,500,9))
axis(2, yaxp=c(0.5,1,10))
lines(data$x, data$y2, type='l',col="blue")
for(i in c(0.55,0.6,0.65,0.7,0.75,0.8,0.85,0.9,0.95)) {
lines(c(50,500),c(i,i),type="l",lty=2,lwd=0.5, col="black")
rm(i)
}
Upvotes: 4