rimager-markdowncaptionfigcaption

How to bring caption (with transperancy) into an image in r markdown


I try to make a basic structure file in r markdown where I can show 2 images. How can I bring the caption with transperancy into the image. And can someone give me a tip how to present a r markdown code as a question? The 3 backticks are working until the next ``` ..., and this is a problem with bunch of code junks. Thank you.

output:

enter image description here.

desired output:

enter image description here

code:

---
title: "test"
author: "TJ"
date: "7 1 2021"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
## R Markdown

![](output.png) 


## desired Output with caption in images

![](desired_output.png) 

Solution

  • You can use image_readand image_annotate from the package magick. Here is an example:

    library(magick)
    yoda <-image_read(path = "yoda.jpg")
    
        
    image_annotate(
      yoda,
      "Figure 1A",
      size = 30,
      color = "white",
      boxcolor = adjustcolor("black", alpha = 0.2), #change the alpha value for more of less transparency
      gravity = "southwest"
    )
    

    enter image description here

    If you want to specify the location of the caption you can replace gravity = "southwest" with with location = " your cordinates". Ex:

    image_annotate(
      yoda,
      "Figure 1A",
      size = 30,
      color = "white",
      boxcolor = adjustcolor("black", alpha = 0.2), #change the alpha value for more of less transparency
      location = "+10+400"
    )
    

    enter image description here

    More about the magick package here.

    About the second question about write Markdown as code in the text: Select the text you want as a code and press tab twice:

    enter image description here