我使用了grid::grid.raster
命令在Rmd
文档中的ggplot下添加了徽标。直到我在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'))
#}
答案 0 :(得分:2)
请在print
周围使用plot
进行渲染。