Content
Now that we have some panels and a layout in mind, let’s start adding content to individual panels.
Text
Text can be added to a panel using the annotate()
function.
We can position the text using the x and y coordinates of our canvas. We can also change text attributes like size, fontface and color.
panel1 <- canvas +
theme_void() +
theme(panel.background = element_rect(fill = '#DEEBF7', colour = '#DEEBF7')) +
annotate("text", x=5.5, y=9, label = "Finding 1", size=15, fontface=2) +
annotate("text", x=5.5, y=2.5, label = "Statistics 1", size=12, fontface=2) +
annotate("text", x=5.5, y=1.5, label = "Units 1", size=12, fontface=2)
panel1
Icons
Icons can be added to the panel using the geom_text()
function.
Icons are provided by Font Awesome, which are free to use and redistribute. You can view the complete library of icons here.
Let’s use the user-md icon as a demonstration.
panel1 <- canvas +
theme_void() +
theme(panel.background = element_rect(fill = '#DEEBF7', colour = '#DEEBF7')) +
geom_text(family='fontawesome-webfont', label=fontawesome('fa-user-md'),
x=5.5, y=5.5, size=75)
Note: If you are using RStudio on Windows, you may have to call a new X11 Window before viewing or the icon might not appear.
Troubleshooting Positioning
If you want to get an idea of how to set your coordinates, you can simply run a panel without theme_void(). This will render the panel with grid lines.
panel1 <- canvas +
theme(panel.background = element_rect(fill = '#DEEBF7', colour = '#DEEBF7')) +
annotate("text", x=5.5, y=9, label = "Finding 1", size=15, fontface=2) +
annotate("text", x=5.5, y=2.5, label = "Statistics 1", size=12, fontface=2) +
annotate("text", x=5.5, y=1.5, label = "Units 1", size=12, fontface=2)
panel1
You can now clearly see the coordinates specified for the text. This is a useful way for troubleshooting positioning, especially if you change font sizes or want a customized layout. This technique also works for checking the positioning of icons.