I'm trying to force my legend to be in lower right corner AND flush against both axes. Right now, the legend defaults to being further inset into the plot than I want it to be (around the middle of the x-axis). I've poked around here and on R documentation and discovered that "inset=" is an optional argument that can be used in the legend function. I THINK this is how I can accomplish what I want. However, when I try only entering one numerical value (inset= 0), the legend ends up in the same place as the default. When I try to enter two numerical arguments (inset= c(0,-2)), the legend won't show up at all. I thought maybe I was using improper syntax and tried inset= 0:-2, but that didn't work either. I've tried playing around with higher values and that causes the legend to become further inset, so I know it's the right argument, but maybe I'm not giving it the right values? I've also tried changing the values for the "xjust=" and "yjust=" arguments and those don't seem to have any notable affect. Does anyone have advice on what I might be doing wrong? Attached are both my code and my current plot output (and arrows showing where I WANT the legend to be):
layout(matrix(c(2,1), 1, 2, byrow = FALSE))
par(pty="s", mar= c(1,3,1,3), mgp=c(1.5,0.5,0))
plot(x1, y1,
xlab="Total X1",
ylab="Total X2",
type= "n",
ylim = c(-3,2),
xlim = c(-2.5,2.5),
cex.lab= 0.7,
cex.axis= 0.7)
text(x1, y1, labels = SedCombined2$Site,
col= c("#D55E00", "#000000", "#009E73", "#0072B2")[as.factor(SedCombined2$Event)],
cex=0.7,
font = 2)
legend("bottomright",
border = "black",
bty= "n",
legend= c("November 2014", "April 2015","November 2015","April 2016"),
text.col = c("#D55E00", "#000000", "#009E73", "#0072B2"),
cex=0.6,
x.intersp = 0.5,
y.intersp = 0.5,
inset = 0)
x2 <- fitSedCombinedISO$points[,1]
y2 <- fitSedCombinedISO$points[,2]
plot(x2, y2,
xlab="Toxic X1",
ylab="Toxic X2",
type= "n",
ylim = c(-3,2),
xlim = c(-2.5,2.5),
cex.lab= 0.7,
cex.axis= 0.7)
text(x2, y2, labels = SedCombined2$Site,
col= c("#D55E00", "#000000", "#009E73", "#0072B2")[as.factor(SedCombined2$Event)],
cex=0.7,
font = 2)
legend("bottomright",
border = "black",
bty= "n",
legend= c("November 2014", "April 2015","November 2015","April 2016"),
text.col = c("#D55E00", "#000000", "#009E73", "#0072B2"),
cex=0.6,
x.intersp = 0.5,
y.intersp = 0.5,
inset = 0)