r - rmarkdown:当 grid.raster 在 `if` 块内时,绘图消失
问题描述
我使用该grid::grid.raster
命令在文档中的 ggplot 下方添加徽标Rmd
。直到我在一个if
块中输入代码之前它工作得很好。
在下面的示例中,如果我启用该if
块,我会得到徽标......没有情节?!?!
---
title: "testing raster logo"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(ggplot2)
```
## R Markdown
```{r cars}
summary(cars)
```
## Including Plots
You can also embed plots, for example:
```{r echo=FALSE, warning=FALSE, message=FALSE, fig.width=10}
library(hrbrthemes)
library(magick)
logo <- image_read("https://i.pinimg.com/originals/2b/d4/79/2bd4796ef4d27df0eea97f88ee18fac6.png")
#if (nrow(iris)>0){
ggplot(iris, aes(x = Petal.Width, y = Petal.Length, color = Species)) +
geom_point() +
labs(title = 'Some plot',
subtitle = 'Petal.Width vs Petal.Length',
x = 'This axis title intentionally left blank',
y = 'This axis title intentionally left blank',
caption = 'iris data') +
scale_color_manual(name = '',
labels = c('Black', 'Red', 'Gray'),
values = c('#000000', '#EC0108', '#ACAEAD')) +
theme_ipsum() +
theme(plot.title = element_text(color = "#EC0108"),
plot.caption = element_text(color = "#EC0108", face = 'bold'))
grid::grid.raster(logo, x = 0.09, y = 0.005, just = c('left', 'bottom'), width = unit(1.75, 'cm'))
#}
解决方案
请print
在您周围使用plot
来渲染它。
推荐阅读
- sql - 如何制作我的 WHERE 语句来过滤基于当前月份的 5 个月动态范围的第一天?
- python - pythonanywhere上的静态文件加载问题
- pandas - 如何使用图例中分配的颜色显示值范围?
- networking - 域“.localdomain”的意义是什么?
- sql - 查询中的对象变量
- google-apps-script - 在表单谷歌表中搜索记录
- azure-active-directory - 为用户颁发可验证凭证时,什么是有效的凭证主体?
- apache - Apache 的缓存问题;css 和 html 没有更新
- css - 更改特定 valueBox 中值的字体大小(flexdashboard)
- r - 使用 group by 聚合 r 中的数据并汇总