Change colours of particular bars in a bar chart

后端 未结 4 1154
轮回少年
轮回少年 2020-12-01 04:47

I\'ve been creating some bar-charts and I was wondering is it possible to colour bars on a chart depending on whether they lie above or below the x-axis?

For clarifi

4条回答
  •  温柔的废话
    2020-12-01 05:09

    I found this page while looking for help on how to colour individual bars in a bar chart according to a factor. I couldn't find any other source of information but thanks to this page, came up with this:

    cols <- ifelse(df$Country == "Greenland", "green","blue")

    It then gets passed into barplot in the usual way as described above:

    barplot(x, col = cols)

提交回复
热议问题