Trying to change bar chart colour to scale_colour_viridis_d()

Hello, I am trying to change the colours on my bar chart to scale_colour_viridis_d() I have put the code in but my colours don't seem to be changing , also there is no error displayed within the terminal. Any help would be much appreciated!

My code as it currently stands:

#install.packages("readxl")
#install.packages("tidyverse")
#install.packages("ggplot2")
#install.packages("viridis")

library(readxl)
library(tidyverse)
library(ggplot2)
library(viridisLite)

url <-'https://static-content.springer.com/esm/art%3A10.1038%2Fs41586-022-05402-9/MediaObjects/41586_2022_5402_MOESM11_ESM.xlsx'
#Create a dataframe from the Excel data
temp <-tempfile()
download.file(url, temp, mode='wb')
myData <- read_excel(path = temp, sheet = "Figure 1i")

myData %>%
#Select the columns and rows that are needed, columns: 2, 4 and 6 and rows 1 to 32.
select(c(2,4,6)) %>%
slice(1:32) %>%

#Rename columns
rename(GSEA_HRC_Marker_Genes = NAME,
Mouse= sign) %>%

#Change column 3 to display as.factor
mutate(across(c(3), as.factor)) %>%

ggplot(aes(x=NES, y= reorder (GSEA_HRC_Marker_Genes, NES), fill = Mouse)) +

geom_bar(stat='identity', width = 0.6, position = position_dodge(width = 0.7)) +

ggtitle("NES Scores of GSEA HRC-Marker Genes") +

xlab("NES")+
ylab("GSEA HRC-Marker Genes") +

scale_y_discrete(labels = c("HALLMARK_HYPOXIA" = "Hypoxia",
"HALLMARK_APICAL_JUNCTION" = "Apical junction",
"GO0016337 CELL-CELL ADHESION" = "Cell-cell adhesion",
"GO0005911 CELL-CELL JUNCTION" = "Cell-cell junction",
"04510 FOCAL ADHESION" = "Focal adhesion",
"GO0031012 EXTRACELLULAR MATRIX" = "ECM",
"GO0005578 PROTEINACEOUS EXTRACELLULAR MATRIX" = "Proteinaceous ECM",
"GO0007156 HOMOPHILIC CELL ADHESION" = "Homophilic cell adhesion",
"04810 REGULATION OF ACTIN CYTOSKELETON" = "Regulation of actin cytoskeleton",
"GO0005604 BASEMENT MEMBRANE" = "Basement membrane",
"GO0030198 EXTRACELLULAR MATRIX ORGANIZATION" = "ECM organization",
"GO0030334 REGULATION OF CELL MIGRATION" = "Regulation of cell migration",
"GO2000145 REGULATION OF CELL MOTILITY" = "Regulation of cell motility",
"GO0045095 KERATIN FILAMENT" = "Keratin Filament",
"04512 ECM-RECEPTOR INTERACTION" = "ECM-receptor interaction",
"GO0046578 REGULATION OF RAS PROTEIN SIGNAL TRANSDUCTION" = "Regulation of RAS signal transduction")) +

scale_x_continuous(position = "top", expand = expansion(mult = c(0, 0.05))) +

scale_fill_discrete(labels=c('Human (FDR < 0.1)', 'Mouse (FDR > 0.1)','Mouse (FDR > 0.1)')) +

scale_color_viridis_d() +

theme(legend.direction = "horizontal", legend.position = "bottom") +
theme(plot.title = element_text(hjust = 0.5)) +
theme(panel.background = element_blank())

you need to use " scale_fill_viridis_d()" as you want to define the fill colour, however then it's duplicated, so better combine both lines to:
scale_fill_viridis_d(labels=c('Human (FDR < 0.1)', 'Mouse (FDR > 0.1)','Mouse (FDR > 0.1)')) +

Also the renaming of the pathway labels could better be performed outstide of the plot, e.g. with:

  # Rename hallmarks
  mutate(pathway = case_when(
    GSEA_HRC_Marker_Genes == "HALLMARK_HYPOXIA" ~ "Hypoxia",
    GSEA_HRC_Marker_Genes == "HALLMARK_APICAL_JUNCTION" ~ "Apical junction",
    GSEA_HRC_Marker_Genes == "GO0016337 CELL-CELL ADHESION" ~ "Cell-cell adhesion",
    GSEA_HRC_Marker_Genes == "GO0005911 CELL-CELL JUNCTION" ~ "Cell-cell junction",
    GSEA_HRC_Marker_Genes == "04510 FOCAL ADHESION" ~ "Focal adhesion",
    GSEA_HRC_Marker_Genes == "GO0031012 EXTRACELLULAR MATRIX" ~ "ECM",
    GSEA_HRC_Marker_Genes == "GO0005578 PROTEINACEOUS EXTRACELLULAR MATRIX" ~ "Proteinaceous ECM",
    GSEA_HRC_Marker_Genes == "GO0007156 HOMOPHILIC CELL ADHESION" ~ "Homophilic cell adhesion",
    GSEA_HRC_Marker_Genes == "04810 REGULATION OF ACTIN CYTOSKELETON" ~ "Regulation of actin cytoskeleton",
    GSEA_HRC_Marker_Genes == "GO0005604 BASEMENT MEMBRANE" ~ "Basement membrane",
    GSEA_HRC_Marker_Genes == "GO0030198 EXTRACELLULAR MATRIX ORGANIZATION" ~ "ECM organization",
    GSEA_HRC_Marker_Genes == "GO0030334 REGULATION OF CELL MIGRATION" ~ "Regulation of cell migration",
    GSEA_HRC_Marker_Genes == "GO2000145 REGULATION OF CELL MOTILITY" ~ "Regulation of cell motility",
    GSEA_HRC_Marker_Genes == "GO0045095 KERATIN FILAMENT" ~ "Keratin Filament",
    GSEA_HRC_Marker_Genes == "04512 ECM-RECEPTOR INTERACTION" ~ "ECM-receptor interaction",
    GSEA_HRC_Marker_Genes == "GO0046578 REGULATION OF RAS PROTEIN SIGNAL TRANSDUCTION" ~ "Regulation of RAS signal transduction"
   )) %>% ```

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.