1

I would like to create conditional formatting for a correlation matrix where cells with correlation coefficients 0.75 to 1 and -0.75 to -1 have green backgrounds with black font (see provided code). However, when I export wb as Excel, all cells in the specified value range have default createStyle() colours (Default is createStyle(fontColour = "#9C0006", bgFill = "#FFC7CE")). I tried to use fgFill instead of bgFill, use only one argument for createStyle() or use only one createStyle() in "corr" sheet which did not help. No matter what I do I can't change the default cell background and font colour. Does anybody have an idea what am I doing wrong?

wb <- createWorkbook()
addWorksheet(wb, sheetName = "corr")
writeData(wb, sheet = "corr", DF, rowNames = F)
conditionalFormatting(wb, "corr",
                      cols = 1:ncol(DF),
                      rows = 1:nrow(DF),
                      type = "between",
                      rule = c(-1, -0.75),
                      operator = createStyle(fontColour = "#191515", bgFill = "#99BC85")
                      )
conditionalFormatting(wb, "corr",
                      cols = 1:ncol(DF),
                      rows = 1:nrow(DF),
                      type = "between",
                      rule = c(1, 0.75),
                      operator = createStyle(fontColour = "#191515", bgFill = "#99BC85")
                      )

1 Answer 1

0

OK, so my mistake. Instead of using the operator argument, there was supposed to be style argument. After this change, the code works as intended.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.