Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing background color for a text annotation to increase contrast and visibility

I'd like to change the background color for my annotate text so that it's green and covers up anything behind it (like the horizontal line in the example below). How do I do that?

ggplot() + 
  geom_hline(yintercept=0) + 
  annotate("text",x=0,y=0,label="Here is a line")

enter image description here

like image 670
Andy Stein Avatar asked Sep 20 '16 20:09

Andy Stein


People also ask

What is the use of changing the background color of a text?

Checking Color Contrast. Changing the color and background color of text is also essential for avoiding problems of web accessibility on your website.

Which background color is best for purple text?

Highlighting Text The best color combinations for highlighting information are as follows: Red (#FF0000) text on a white (#FFFFFF) background. Purple (#990099) text on a white (#FFFFFF) background. Yellow (#FFFF00) text on a Prussian blue (#003366) background.


1 Answers

Try geom_label instead:

ggplot() + 
  geom_hline(yintercept = 0) + 
  labs(x = "", y = "") +
  geom_label(aes(x = 0, y = 0, label = "Here is a line"), fill = "green")

enter image description here

like image 69
Martin Schmelzer Avatar answered Oct 29 '22 16:10

Martin Schmelzer