Home > Software engineering >  ggplot - how to "highlight" one segment of a curve
ggplot - how to "highlight" one segment of a curve

Time:11-16

I have a plot like this:

library(ggplot2)

ggplot()  
  geom_function(fun = ~ 2*-.x^2   2*.x   3)

enter image description here

Now I want to "highlight" one segment of the curve as on the following photo made in Paint:

enter image description here

How can I achieve that?

CodePudding user response:

You can add an xlim argument to a second geom_function

library(ggplot2)

ggplot()  
  geom_function(fun = ~ 2*-.x^2   2*.x   3)  
  geom_function(fun = ~ 2*-.x^2   2*.x   3, xlim=c(.25, .5), color = 'blue', size = 2)

Created on 2022-11-15 by the reprex package (v2.0.0)

  • Related