【问题标题】:Adding ggplot code chunk to RMarkdown breaks HTML tabset将 ggplot 代码块添加到 RMarkdown 会破坏 HTML 选项卡集
【发布时间】:2021-02-25 20:50:50
【问题描述】:

这里是新的 R 程序员和 SO 的新手...

我有一个 RMarkdown 文档,我在其中创建了标签。

由于某种原因,当我尝试编织时,带有 ggplot 的块似乎破坏了 tabset 代码,因为当我省略这些块时,文档会按原样显示。

当 ggplot 代码 include = FALSE 时,会包含选项卡,但下面的代码似乎会破坏选项卡。任何解决方法的想法?这是一个错误,还是我的新手?提前谢谢...

## Options {.tabset .tabset-pills}

```{r Barplot, include=TRUE,echo=FALSE}

barplot_group_count <- ggplot(data=group_count, aes(x=Group, y=n)) + 
  geom_bar(stat = "identity") +
  labs(title = "Count of Groups According to PSA Attributes") +
  coord_flip()

barplot_group_count
```

【问题讨论】:

  • 您是否尝试在选项卡标题和代码块之间添加额外的白线? (曾经对我有用)
  • @teunbrand 是的,我刚刚又试了一次,但标签仍然丢失。不过谢谢,我知道有时确实有效,但在这里不行。

标签: r ggplot2 tabs r-markdown


【解决方案1】:

我发现如果我包装了对 ggplotly() 的调用,就会显示图表。

barplot_group_count <- ggplot(data=group_count, aes(x=Group, y=n)) + 
  geom_bar(stat = "identity") +
  labs(title = "Count of Groups According to PSA Attributes") +
  theme(plot.margin=unit(c(2, 1.5, 1.5, 1.5),"cm"))+
  coord_flip()

ggplotly(barplot_group_count)

【讨论】:

    猜你喜欢
    • 2016-01-22
    • 2011-03-24
    • 2016-03-04
    • 1970-01-01
    • 2013-11-08
    • 1970-01-01
    • 1970-01-01
    • 2011-01-03
    • 2015-04-02
    相关资源
    最近更新 更多