How to highlight text inside a plot created by ggplot2 using a box in R?

There might be many ways to highlight text inside a plot but the easiest one would be using geom_label function of ggplot2 package, with the help of this function we can put the required text and the aesthetics of that text by using a single line of code. It is highly recommended that we should use geom_label function with desired specifications.

Example

library(ggplot2)
ggplot(df,aes(x))+geom_histogram(bins=30)+geom_label(aes(x=6,y=450,label="Normal Distribution"),fill="red")

Output

Updated on: 2026-03-11T23:22:53+05:30

295 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements