在rmarkdown文档

时间:2016-05-28 06:04:05

标签: r ggplot2 r-markdown

我正在尝试使用knitr编织为pdf,在rmarkdown中的ggplot2条形图的标题中显示一个真正的减号。

这是玩具数据:

gene <- rep(c("Gene \u2013", "Gene +"), times = 4)
group <- rep(c("A", "B"), each = 2, length.out = 8)
prepost <- rep(c("Pre", "Post"), each = 4)
score <- rnorm(8, 7, 2)

df <- data.frame(gene, group, prepost, score)

注意我已使用unicode \u2013作为真正的减号

现在绘制数据:

p <- ggplot(df, aes(y = score, x = group, fill = prepost)) +
            geom_bar(stat = "identity", position = position_dodge(width = 0.9), size = 0.1) +
            facet_wrap(~gene, nrow = 1) + 
            scale_fill_manual(values = c("#999999", "#666666")) +
            theme_bw()

p

这里的基因阴性组显示真正的减号。

但是当我们在rmarkdown中的一个块中包含相同的代码时:

---
title: "Why is a true Minus Sign so Hard To Find?"
author: "Llew Mills"
date: "28 May 2016"
output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## Plot

```{r pressure, echo=FALSE}
library(ggplot2)

gene <- rep(c("Gene \u2013", "Gene +"), times = 4)
group <- rep(c("A", "B"), each = 2, length.out = 8)
prepost <- rep(c("Pre", "Post"), each = 4)
score <- rnorm(8, 7, 2)

df <- data.frame(gene, group, prepost, score)

p <- ggplot(df, aes(y = score, x = group, fill = prepost)) +
            geom_bar(stat = "identity", position = position_dodge(width = 0.9), size = 0.1) +
            facet_wrap(~gene, nrow = 1) + #splits into two graphs: gene negative and gene positive
            scale_fill_manual(values = c("#999999", "#666666")) +
            theme_bw()
p
```

减号已替换为...

有没有人知道如何在rmarkdown编织中显示真正的减号到pdf?

0 个答案:

没有答案