This is for an art project. I've created a scatterplot with many dots of 5 different colours. I want to create a legend that is completely separate from the plot, as in it is not on the plot, nor beside the plot, but is in it's own window so I can save the legend as it's own .pdf file. This is so I can have my plot and legend printed separately as they well be hung in a gallery as separate pieces.
All I want is to recreate this image using R:
Is this even possible?
Thanks,
Jay
In order to draw our legend outside of the plotting area, we can use a combination of the “topright” argument and an additional specification of inset. The “topright” argument specifies that the legend should be in the upper right corner of the graph.
In R you can add a legend to any plot using the legend() command. You can also use the legend = TRUE parameter in the barplot() command. The barplot() command is the only general plot type that has a legend parameter (the others need a separate legend).
legend() function in R Programming Language is used to add legends to an existing Plot.
Sure. Just start from an empty plot and then use legend as you would if there were a plot.
plot(NULL ,xaxt='n',yaxt='n',bty='n',ylab='',xlab='', xlim=0:1, ylim=0:1)
legend("topleft", legend =c('Sugar maple', 'White ash', 'Black walnut',
'Red oak', 'Eastern hemlock'), pch=16, pt.cex=3, cex=1.5, bty='n',
col = c('orange', 'red', 'green', 'blue', 'purple'))
mtext("Species", at=0.2, cex=2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With