0

I am plotting the Year over Year (YoY) Percentage Change in GDP for a country and would like to have the negative YoY values be highlighted as "RED" text in callout boxes on the graph.

I have created a graph and added the callouts for the values using "geom_label". I want to change the negative values in the geom_label callouts to "RED" text, while keeping the positive values in the geom_label callouts as "BLACK" text. Please see the code below:

ggplot(data = gdp_line) +
  aes(x = Year, y = YoY * 100, group = 1) + 
  geom_line(colour = "blue")  +
  labs(y = "GDP YoY % Change", x = "") +
  ggtitle("GDP YoY % Change (at Constant Prices: 2007 as Base Year)") +  
  
**Creation of Callout Text Boxes with YoY % Change Values**  
**I want to make the negative YoY % Change Values "RED" text**  
**I want to keep the positive YoY values as "BLACK" text**
  
  geom_label(aes(label = round(YoY * 100, digits = 2)), size = 2.5, fontface = "bold") + 
  scale_y_continuous(labels = function(x) paste0(x,"%")) +
  labs(caption = "Source: STATIN Jamaica")

enter image description here

  • 1
    The post this was marked as a duplicate of is about changing the color of the line above and below a threshold, but you can apply all those same techniques to your `geom_label` color instead. In fact, doing that for text is even simpler than for lines, because you don't have to worry about interpolation between points – camille Feb 23 '22 at 00:58

0 Answers0