

We can color each bar of the barplot with a different color by providing a vector of colors. So the plot is colored according to the rgb value. Here, we have passed rbg() to the col parameter inside barplot(). We can directly pass rgb() to the col parameter as: # create a vector named tempīarplot(temp, col = rgb(0.3, 0.7, 0.9), main="Using RGB Values")
LIST OF R STUDIO COLORS CODE
This function returns the corresponding hex code discussed above. The rgb() function in R allows us to specify red, green and blue components with a number between 0 and 1.

#c00000 - this hex is composed of 75.3% red, 0% green and 0% blue.In the above example, we have passed the hex value for the col parameter inside the barplot() function.
LIST OF R STUDIO COLORS HOW TO
Let's take a look at how to implement hex values as colors in R, # create a vector named tempīarplot(temp, col="#c00000", main="#c00000")īarplot(temp, col="#AE4371", main="#AE4371") Where the RR is for red, GG for green and BB for blue and value ranges from 00 to FF.įor example, #FF0000 would be red and #00FF00 would be green similarly, #FFFFFF would be white and #000000 would be black.

We define a color as a 6 hexadecimal digit number of the form #RRGGBB. In R, instead of using a color name, color can also be defined with a hexadecimal value. For example, col=colors() is the same as col="yellow3". We can color our plot by indexing this vector. Here, the colors() function returns a vector of all the color names in alphabetical order with the first element being "white". "antiquewhite4" "aquamarine" "aquamarine1" "antiquewhite1" "antiquewhite2" "antiquewhite3" Output "white" "aliceblue" "antiquewhite" We can take a look at them all with the colors() function, or simply check this R color pdf. Using Color Names to Change Plot Color in R Try replacing it with "green", "blue", "violet", etc. Here, we have passed col = "coral" inside the barplot() function to color our barplot with coral color. # create a vector named tempīarplot(temp, col="coral", main="With coloring") We use the following temp vector to create a barplot throughout this section. For example, if we want our plot to be a red color, we pass col = "red". We can specify the name of the color we want as a string. This is generally done with the col graphical parameter. We can visually improve our plots by coloring them.
