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

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

colors

colors

- [Instructor] Your graphs will look better if you add a little bit of color to them. And in order to add color to an R function, you need to use some color commands that are unique to R. So let's take a look at colors and colorRampPalette. First of all, colors, C-O-L-O-R-S, parentheses just lists all of the colors available and predefined in R. It's just a vector with a lot of names in it. By itself, it's not very useful. If you wanted to look at the first three colors in the colors vector, you could type in colors()[1, say 10, and that'll Give you 10 Colors. Now, to use a color in a graph, you're probably gonna want to identify a number of different elements by a number of different colors, and that's where colorRampPalette comes in. So I'm gonna define a function we'll call mycolorpal, and into that function, I'm going to put colorRampPalette. ColorRampPalette wants me to give it a couple of colors, so I'll create a vector, and in that vector I'm going to use the colors command…

Contents