Personally I would create a new variable in the table (a fill_col column) with value according to your filter. Then you can use this variable on the fill aesthetic.
It is a wild guess as we need a reprex to be on the same page (follow @mara advice, but i would modify you code like this
library(tidyverse)
perf.project <- read.csv2("test2.csv",header=TRUE,sep=";",stringsAsFactors=FALSE,encoding="UTF-8",dec=".",check.names=FALSE)
perf.project.tdy <- perf.project %>%
gather("types", "perf", 6:6) %>%
# Create the variable you need for the plot
mutate(pas = factor(pas, levels = unique(pas), ordered=TRUE),
fill_col = case_when(
perf > 0 ~ "green",
perf <= -4 ~ "red",
TRUE ~ "orange"
))
barwidth <- 0.95
# ggplot work on a data.frame and you need to provide variables (columns) of that DF (without any $)
ggplot(perf.project.tdy, aes(x = pas , y = perf)) + # you provide fill after
geom_col(fill = fill_col,
width = barwidth) +
# aes x and y are already provided
geom_text(aes(label=paste(perf, "%")), vjust=1.6, color="black", size=3.5)
It may not work as I don't have your data to test. Basically, what I wanted to show:
-
tidyverse has tools like dplyr
to efficiently work with data. (like case_when for recoding more than 2 level and mutate to modify variables. )
- ggplot2 works a data.frame (provide in
data argument), then you map variables (columns) to aesthetics and scales. You don't need to provide vector value with $. Just the column name.
- Knowing that, put everythink in your data. You can add a column with value corresponding to color for fill aesthetics.
library(ggplot2)
df <- data.frame(trt = c("a", "b", "c"), outcome = c(2.3, 1.9, 3.2), fill_col = c("red", "green", "blue"))
ggplot(df, aes(trt, outcome)) +
geom_col(aes(fill = fill_col))

Created on 2018-11-01 by the reprex package (v0.2.1)
Hope it helps.