ROIpad ← Back to Search
stackoverflow › answer

Answer to: Highlight all values from single column

Score: 2
Answered: Jan 28, 2026
User Rep: 78,147
You were right about scale_color_manual, the code below uses it. Color by name and then change the colors to the colors you want, in this case, gene1 is red and all others black. The colors vector clrs is created based on the original data.frame, so if there are more genes the code below should still work. suppressPackageStartupMessages({ library(ggplot2) library(dplyr) library(tidyr) }) # create a colors named vector genes <- grep("gene", names(df1), value = TRUE) num_genes <- length(genes) # first a vector of all black colors clrs <- rep("black", num_genes) |> setNames(genes) # now, assign the chosen gene its color clrs["gene1"] <- "red" df1 %>% pivot_longer(!Indiv, names_to = "gene") %>% ggplot(aes(x = Indiv, y = value)) + geom_point(aes(color = gene), size = 2) + scale_color_manual(values = clrs) Created on 2026-01-28 with reprex v2.1.1 Data df1 <- read.table(text = " Indiv gene1 gene2 gene3 A 0.5 -0.4 0.02 B 1.0 0.05 -0.3 C -0.8 0.1 0.15", header = TRUE) df1 #> Indiv gene1 gene2 gene3 #> 1 A 0.5 -0.40 0.02 #> 2 B 1.0 0.05 -0.30 #> 3 C -0.8 0.10 0.15 Created on 2026-01-28 with reprex v2.1.1
r ggplot2 gghighlight
View Question ↗
Question
Parent Entity
Score: 4 • Views: 66
Site: stackoverflow