从R中嵌套的ggplot中删除索引号

问题描述 投票:1回答:1

我尝试使用rmarkdown进行编译时从具有ggplot图的嵌套列中删除索引号。我曾尝试更改块选项,但我不认为答案在那里。我读到cat()可能有效,但不确定如何包括在内。

这里是代表:

---
title: "test"
output: pdf_document
---

```{r setup, include=FALSE}
    library(ggplot2)
    library(purrr)
    library(knitr)
    library(tinytex)

    knitr::opts_chunk$set( warning = FALSE, message = FALSE, comment = NA)

  df <- iris %>%  
         group_by(Species) %>%  
         nest() %>%  
         mutate(
             plot= purrr::map(data, ~ ggplot(., aes(Sepal.Length, Sepal.Width)) + geom_point()))

```

```{r}
   df %>% 
      filter(Species == "setosa") %>% 
      select(plot) %>% 
      pull()
``` 

enter image description here

将不胜感激。

最佳

r ggplot2 purrr
1个回答
1
投票

我们可以pluck list元素

library(dplyr)
library(purrr)
df %>% 
   filter(Species == "setosa") %>%
   ungroup %>%
   pull(plot) %>% 
   pluck(1)

或者可以通过]使它更简单>

df %>% 
   filter(Species == "setosa") %>%
   ungroup %>% 
   pluck("plot", 1)
    
© www.soinside.com 2019 - 2024. All rights reserved.