R script - Print legend outside plot box

Can you please help ? My R script produced the attached graph. The legend is messy and I will want it outside the box (outside plotting area). How do I do this

Part of the script for legend is shown below:

par(new=TRUE)
o=-log10(sort(d22$V1, decreasing=F))
e=-log10(ppoints(length(o)))
qqplot(e, o, pch=20, cex=1, col="red", main="Cholesterol Whole Genome Analyses with diff kinship matrices", xlab="-log10(expected p value)", ylab= "-log10(observed p value)", xlim=c(0, max(e)), ylim=c(0, 30))
legend(0, 30, c("KM_chr1Excl", "KM_chr2Excl", "KM_chr3Excl", "KM_chr4Excl","KM_chr5Excl","KM_chr6Excl","KM_chr7Excl","KM_chr8Excl","KM_chr9Excl","KM_chr10Excl","KM_chr11Excl", "KM_chr12Excl", "KM_chr13Excl", "KM_chr14Excl","KM_chr15Excl\
","KM_chr16Excl","KM_chr17Excl", "KM_chr18Excl", "KM_chr19Excl","KM_chr20Excl", "KM_chr21Excl","KM_chr22Excl"), lty=1,lwd=8,col =c("Black", "Blue", "Pink","khaki4","coral", "azure", "cyan","brown","gold","deeppink","lawngreen","gray", "\
lightblue","navy", "bisque3","blueviolet", "burlywood", "darkgreen", "darkmagenta", "darkorange3","darksalmon", "red"), pch=c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1))
lines(e,e, col="grey")
dev.off()