Question Details

No question body available.

Tags

r ggplot2 gghighlight

Answers (3)

January 28, 2026 Score: 2 Rep: 78,147 Quality: Medium Completeness: 80%

You were right about scalecolormanual, 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 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

January 28, 2026 Score: 2 Rep: 34,090 Quality: Low Completeness: 70%
library(ggplot2)
library(gghighlight)

df |> tidyr::pivotlonger(!Indiv) |> ggplot(aes(x = Indiv, y = value)) + geompoint(aes(group=name, color = name), size = 2) + gghighlight(name == "gene1", usedirectlabel = FALSE, usegroupby = FALSE, unhighlightedparams = list(color = "black")) + themebw() + theme(legend.title = element_blank())

Created on 2026-01-28 with reprex v2.1.1

January 29, 2026 Score: 0 Rep: 22,336 Quality: Medium Completeness: 80%

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