abi*_*hat 4 html r image r-markdown
我想在我的降价文档中包含一张来自网络的图片,但我只想要图片的左侧部分。我搜索了如何使用 rmarkdown 修剪图片,但我什么也没找到......
这是一个例子
---
title: "How to trim?"
output: html_document
---
```{r setup, include=FALSE}
library(knitr)
knitr::opts_chunk$set(echo = TRUE, fig.align = 'center')
```
Include picture
```{r pic}
include_graphics("http://ggplot2.tidyverse.org/README-example-1.png")
```
Run Code Online (Sandbox Code Playgroud)
这给了我这个 HTML 输出。
如果我想修剪图例(右侧约 20% 的部分),我该怎么做?
我接受任何类型的答案:相对或绝对规范、rmarkdown 或 html 解决方案,...
谢谢!
您可以使用:
library(magick)
crop <- function(im, left = 0, top = 0, right = 0, bottom = 0) {
d <- dim(im[[1]]); w <- d[2]; h <- d[3]
image_crop(im, glue::glue("{w-left-right}x{h-top-bottom}+{left}+{top}"))
}
"http://ggplot2.tidyverse.org/README-example-1.png" %>%
image_read() %>%
crop(right = 210)
Run Code Online (Sandbox Code Playgroud)