简体   繁体   中英

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:

在此处输入图像描述 .

desired output:

在此处输入图像描述

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) 

You can use image_read and 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"
)

在此处输入图像描述

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"
)

在此处输入图像描述

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:

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM