From the course: R for Data Science: Lunch Break Lessons

Unlock this course with a free trial

Join today to access over 24,900 courses taught by industry experts.

legend

legend

- [Instructor] When you create a plot in R you're going to want to identify the data series that you're using. And for that you'll want to create a legend. So let's look at the R legend command for demonstration I've created a function called new graph and each time I call new graph, I'll get a clean graph and you'll see me use this quite frequently during this session. Let's add a legend to our graph and to do that I'll use the legend command as shown in line four. Now this is the basic legend I can select the first word and then hit run. And you'll see that my plot on the right hand side now has a legend. This is a legend and positive negative slope and random. There are several ways that we can improve this legend. Let's first talk about position. Right now it's positioned at the bottom, but I can also position it at the bottom left just by changing X equal to that. If I hit new graph to clear the graph and then the…

Contents