How to set colors in the barplot function in R language?

In R language, you can use the col parameter to set the color of a barplot. Here is the specific method:

  1. abridge
barplot(heights, col = "red")
  1. make more space
barplot(heights, col = c("red", "green", "blue"))
  1. rainbow() – a function that generates a sequence of colors in the order of the colors of a rainbow.
  2. generate a color palette based on heat levels
  3. generate a list of colors
  4. collected
  5. create a rainbow
barplot(heights, col = rainbow(7))
  1. Create a color palette with smoothly changing colors
  2. short for column
myColors <- colorRampPalette(c("red", "white", "blue"))
barplot(heights, col = myColors(length(heights)))

Please choose the appropriate method to set the color of the bar plot according to your needs.

bannerAds