0

I am trying to create a textbox to accompany a complex visualisation developed in ggplot2.

My code is:

library(ggplot2)
library(ggtext)

text<-"How to read this infographic?<br>
<br>
There is a block of text here that goes over<br>
several lines<br>
<img src='~/pics/icons8-forest-50.png' width='20' float= 'left' />  There is a very very very very very very long sentence here <br>
and more text here.<br>"


textbox<-ggplot(data = data.frame(x = 0:1, y = 1:10)) +
  labs(subtitle = text) +
  theme_void() +
  theme(plot.subtitle = ggtext::element_markdown(size=8,
                                                 hjust = 0,
                                                 halign = 0,
                                                 colour="white"),
        plot.margin = unit(c(0,0,-2,0), "lines"),
        plot.background = element_rect(fill = "black",
                                       colour = "black"),
        
        plot.title.position  = "plot"
  )

The output I get looks like the picture below

enter image description here

I would like to improve the visual result by

  1. making both lines that follow the picture (There is a very very very very very very long sentence here and more text here. )fit nicely on the right side of the picto, and
  2. fully justify the text in the textbox overall.
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Jelo A
  • 39
  • 4

0 Answers0