Search code examples
rhighlightgeom-col

Highlight bars >= 5 in one column only, geom_col(), R


I created the following column plot using ggplot geom_col and highlighted the columns that are >= 5. The goal is to only highlight values >= 5 in the Structure column and leave the other columns not highlighted.

The data frame FC_TS has three columns: Last Name, Feature, Valuewhich I can't publish for data protection reasons. Featurecan be either Action, Flexibility_Thinking, Reflection, Structure and Value can be 1-7. level_order only changes the original order of the Features.

Here is my code so far, please help!

TS_bar <-
  ggplot(FC_TS, aes(x = factor(Feature, level = level_order), y = Value, colour = Value >= 5)) +
   scale_colour_manual(name = 'High Structure', values = setNames(c('red', NA),c(T, F))) + geom_col(aes(fill = `Last Name`), position = "dodge") + coord_cartesian(ylim = c(1, 7)) + scale_y_continuous(n.breaks = 7) + theme_bw() 

geom_col() so far


Solution

  • Try:

    ggplot(FC_TS, aes(x = factor(Feature, level = level_order), y = Value, colour = (Value >= 5 & Feature == “Structure”)))