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

How to changes words in a charts title based on condition?

I would like the title of my plot to change based on if the supply is over or under the estimate. The estimate of the supply is in DF$Supply.. If it is positive its over the estimate and if it is negative it’s under the estimate. How can i set up the condition to check the DF$Supply and chose the right title.

If the supply is OVER the estimate i would like the title to be this:

labs(title=paste("In 2021-2030 the supply is over the estimate by", DF$Supply)

If the supply is UNDER the estimate i would like the title to be this:

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

labs(title=paste("In 2021-2030 the supply is under the estimate by", DF$Supply*-1)

If the supply is equal to the estimate the title is (this means that DF$Supply = 0):

labs(title="In 2021-2030 the supply matches the estimate")

>Solution :

Im not sure if this is going to work, its always better when you provide the dataset…

labs(title = case_when(
      DF$Supply >= 1 ~ paste("In 2021-2030 the supply is over the estimate by", DF$Supply),
      DF$Supply < 0 ~ paste("In 2021-2030 the supply is under the estimate by", DF$Supply*-1),
      DF$Supply == 0 ~ "In 2021-2030 the supply matches the estimate"
    ))
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