Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

ggplot – how to "highlight" one segment of a curve

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

How can I achieve that?

>Solution :

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)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading