If you choose to stay with the base
plotting functions in R, you can address each of your concerns. The following response is simply meant to review and illustrate previous comments from this question and include other SO-related materials for additional assistance.
First, let's tackle the y-axis issue. As suggested in the original comments, you are currently calling the axis
command twice with respect to the y-axis. By identifying your desired y-axis limits early on, they can be easily applied with the ylim
argument.
df<-data.frame(anim=c(1.72,1.6,1.7,1.74,1.8),mirr=c(.80,.95,1.13,1.17,1.26))
gmin<-min(df) #<---- ESTABLISH MIN Y-AXIS VALUE
gmax<-max(df) #<---- ESTABLISH MAX Y-AXIS VALUE
plot(df$anim,type="o",col="blue",ylim=c(gmin,gmax),axes=FALSE,ann=FALSE)
box()
axis(1,at=1:5,lab=seq(0.5,0.9,0.1))
axis(2,seq(gmin,gmax,0.2),las=2)
lines(df$mirr,type="o",pch=22,lty=2,col="red")
title(main="corr vs dprime",col.main="forestgreen",font.main=4)
title(xlab="Correlation",col.lab="black",font.main=4)
title(ylab="dprime",col.lab="black",font.main=4)

Second, the legend can be placed either within the plotting area or placed outside. As suggested in the original comments, type in ?legend
and review the x, y
arguments for positioning your legend. This would likely be your best approach since your range of x and y values are small, which would allow for easy legend placement. Although less specific, you can also use keywords to specify the legend's position (?legend
under Details) such as "bottomright", "bottom", "bottomleft", "left", "topleft", "top", "topright", "right" and "center". For instance:
legend('bottomright', c("anim", "mirr"), cex=0.8,col=c("blue","red"), pch=21:22, lty=1:2)

where adjusting arguments, such as x.intersp
, y.intersp
, and cex
, will allow you to change the legend's shape and relative size.
Additionally, you can create your legend outside of the plotting area as shown by the previous answer using ggplot2
. Several options are recommended in the following SO answer: Plot a legend outside of the plotting area in base graphics?. The most popular methods take advantage of the xpd
argument in par
followed by the x, y
or inset
arguments from legend
.
Without adjusting margins about the plotting area, you can simply select x and y parameters so the legend is placed properly while not overlapping other items. For instance:
par(xpd=TRUE)
legend(4.5,2.1,c('anim','mirr'),cex=0.8,col=c('blue','red'),pch=21:22,lty=1:2)

where the box about the legend can be controlled using the bty
argument in legend
.
If you would prefer your legend more like the previous answer, you will need to review the mai
, mar
, and oma
arguments in par
so that the legend is properly displayed (see here). Once configured, you can then specify your legend's position outside of the plot area using inset
argument in legend
:
par(oma=c(0,0,0,1),mar=c(5.1,4.1, 4.1, 5.1),xpd=T)
plot(df$anim,type="o",col="blue",ylim=c(gmin,gmax),axes=FALSE,ann=FALSE)
box()
axis(1,at=1:5,lab=seq(0.5,0.9,0.1))
axis(2,seq(gmin,gmax,0.2),las=2)
lines(df$mirr,type="o",pch=22,lty=2,col="red")
title(main="corr vs dprime",col.main="forestgreen",font.main=4)
title(xlab="Correlation",col.lab="black",font.main=4)
title(ylab="dprime",col.lab="black",font.main=4)
legend('right',inset=c(-0.4,0),c('anim','mirr'),cex=0.8,col=c('blue','red'),pch=21:22,lty=1:2)

Alongside other answers, I hope this small review helps your current situation and demonstrates R's flexibility using base
and other plotting functions. Credit goes to previous users and their comments along with the other SO answers.