O'Reilly logo

Learning Shiny by Hernán G. Resnizky

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Legends

As in lines() and points(), legend() is a function that needs to be called after the plot creation. legend() contains numerous arguments and most of them are optional.

The only mandatory arguments in legend() are x and legend, that is, the position and the texts that are passed to the legend. It is important to keep in mind that if y is not passed and a value is passed in x, this will be considered as a value in the vertical axis and the position with regard to the horizontal axis will be 1. If both the values (x and y) were specified, then the first will be the position in the horizontal axis and the second will be the position in the vertical axis.

The following two examples illustrate this difference. In the first one, as only one value ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required