Reputation: 55
I use the following R plot commands to create a plot - I managed to find the "right" commands after quite many look-ups in Google - but it is still not perfect:
x = c(0.1,0.2,0.3,0.4);
y = c(100,200,300,400);
z = c(81,82,83,87);
w = 150;
v = 85.5;
plot(x,y, type="l", lwd=4, xlab="threshold", ylab="seconds");
points(x, y, col="red", cex=2, pch=19);
abline(h=w, col="red", lwd=4);
par("usr");
par(usr = c(par("usr")[1:2], 80,90));
axis(4, lwd=4);
points(x, z, col="blue", cex=2, pch=19);
points(x, z, type="l", lwd=4);
abline(h=v, col="blue", lwd=4);
What I am looking for is a few things:
adding a text next to the right y axis. I saw somewhere someone suggested using mtext, but it is not working for me. Isn't there a way to have a label attached to the right y axis with the axis command? adding ylab or lab doesn't help.
I want the color of the text next to the y axis to be blue and red (so that it is clear, according to the dots in the graphs, which curve goes with which axis). Is that possible to color only the label of the y axis? (well, first I have to get a label for the right y axis!)
I want to make the lines of the left y axis (and the tick marks) as thick as they are in the right y axis. Same for the x axis. Is that possible?
Upvotes: 0
Views: 497
Reputation: 93938
Try something like this:
par("mar")
par(mar = c(par("mar")[1:3], 5.1))
plot(x,y, type="n", lwd=4, ylab="", xlab="threshold", xaxt="n",yaxt="n")
axis(1,lwd=4)
axis(2,lwd=4)
points(x, y, col="red", cex=2, pch=19)
abline(h=w, col="red", lwd=4)
par("usr")
par(usr = c(par("usr")[1:2], 80,90))
axis(4, lwd=4)
points(x, z, col="blue", cex=2, pch=19)
points(x, z, type="l", lwd=4)
abline(h=v, col="blue", lwd=4)
mtext("Your text", side = 4, col = "blue",line=3)
mtext("seconds", side = 2, col = "red",line=3)
Upvotes: 2