ROIpad ← Back to Search
stackoverflow › answer

Answer to: Highlight all values from single column

Score: 0
Answered: Jan 29, 2026
User Rep: 22,336
Here's one way to highlight just one gene. Create a function that accepts your data and the gene number that you want to highlight: plot_gene <- function(data, gene_num) { gene_val <- paste0("gene", gene_num) other_genes <- "Others" # Create named vectors for the point colors and sizes cols <- setNames(c("red", "grey50"), c(gene_val, other_genes)) sizes <- setNames(c(2, 1), c(gene_val, other_genes)) data %>% pivot_longer(!Indiv) %>% mutate(Gene=ifelse(name==gene_val, name, other_genes)) %>% ggplot(aes(x = Indiv, y = value)) + geom_point(aes(col = Gene, size = Gene)) + scale_color_manual("Gene", values = cols) + scale_size_manual("Gene", values = sizes) } plot_gene(df1, gene_num=3) ## Packages library(ggplot2) library(dplyr) library(tidyr) ## Data set.seed(26) GENES <- matrix(rnorm(26*50), 26) df1 <- setNames(data.frame(LETTERS, GENES), c("Indiv", paste0("gene", 1:50)))
r ggplot2 gghighlight
View Question ↗
Question
Parent Entity
Score: 4 • Views: 66
Site: stackoverflow