Can someone help me debug this code to generate a normalization graph based on the data "GSE233767_mRNA_Expression_Profiling.xlsx" (download link: GEO Accession viewer )
This is my code to generate a normalization graph but it keeps giving me the same errors " Error in mutate()
:
In argument:
across(all_of(cols), ~./sum(.))
.
Caused by error in across()
:
! Can't compute column ...10
.
Caused by error in sum()
:
! invalid 'type' (character) of argument"
library(tidyverse)
library(readxl)
library(ggplot2)
#load data
data <- read_excel("file-path-to-data")
# Select columns for normalization
cols <- colnames(data)[10:17]
# Convert columns to character type
for (col in cols) {
data[[col]] <- as.character(data[[col]])
}
# Define gene_id variable
gene_id <- data$gene_id
# Normalize selected columns
normalized_data <- data %>%
mutate(across(all_of(cols), ~ ./sum(.)))
# normalization plot
ggplot(normalized_data, aes(x = gene_id, y = value)) +
geom_bar(stat = "identity", fill = "steelblue") +
labs(x = "Gene ID", y = "Normalized Value", title = "Normalization Graph") +
theme_minimal()