Share the Gallery !Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInEmail this to someone


To add a legend in an R plot, use the legend() function. Main arguments:

  • topright : where do you want to add the legend ? You can put : “bottomright”, “bottom”, “bottomleft”, “left”, “topleft”, “top”, “topright”, “right”, “center”).
  • legend = c(“name1”, “name2”) : names you want to show.
  • col = c(“red”, “blue”) : colors of the symbols
  • pch = 15 : type of symbols (see graph # to know what symbol number you need
  • bty = “n” : If you don’t want a box around the legend. Write “o” if you want one
  • pt.cex = 2 : Size of the symbols
  • cex = 0.8 : Size of the text
  • text.col = “black” : color of the text
  • horiz = TRUE : legend in column or in row ?
  • inset = c(0.1, 0.1) : % (from 0 to 1) to draw the legend away from x and y axis
  • You can also give the X and Y coordinate of the legend: legend(3, 5, legend = c(“A”, “B”))

Not what you are looking for ? Make a new search !

3D abline add aggregate animation arrows at axis barplot basics beside bg border boxplot boxwex breaks bty cex cex.axis circular plot cmdscale col color Colors cor cut d3.js dataArt dendrogram density dist factor font ggplot2 hclust hist Histograms horiz hsv ifelse Igraph image ImageMagick Important ! inset jitter labels las lattice layout leafletR legend legend.text levelplot levels library lines lm lty lwd main map Maps mar mfrow mfrox mgp Miscellaneous model mtext mtxt names nlevels oma order package par paste PCA pch pie plot plotly points polygon predict pt.cex pty R radarchart rect reorder rgb rgl Ring scatterplot segments stacked-area table tag_ tag_for_slider testnumber1 text tick Time series title toto tutu type VennDiagram violin-plot width wordcloud xaxt xlab xlim xyplot yaxt ylab ylim zetag

You can search a media by theme with the tag cloud above.

Leave a Reply

Be the First to Comment!

Notify of