0

我在 .Rmd 中编织 ggplot 时遇到问题。

简要总结:我的输入是一个.Rmd,我的输出是通过officedown的word文档。

我的问题:当我运行我的块时我的 scale_y_continous 看起来不错(只有整数没有逗号)但是当我在我的 word doc 上看到它时看起来很糟糕(带小数)。为什么会这样?我使用 scales::label_number(accuracy = 1) 它,它在我的块中工作,但是在编织它时,它忽略了这个参数。

在我的 r 块 .Rmd 中:(第一张图片) 第一张图片

用我的话文档:(第二张图片)

第二张图片

我的数据:

> dput(res1)
structure(list(dia_de_respuesta = structure(c(1646220962, 1646209714, 
1646181947, 1646175790, 1646158653, 1646153675, 1646153184, 1646147789, 
1646139472), class = c("POSIXct", "POSIXt"), tzone = "UTC"), 
    email_address = structure(c("mildtieezc3@gmail.com", 
    "dmrev@pucp.edu.pe", "juanguelmendozacampos@hotmail.com", 
    "winifudy@gmail.com", "puche.cinthia@outlook.com", 
    "profoer.harabino@gmail.com", "gcua@claretiano.edu.pe", 
    "diaz.ro.nelber@gmail.com", "nemy88@gmail.com"), label = "email_address", format.spss = "A100", display_width = 50L), 
    Respuesta = c("Respuesta completa", "Respuesta completa", 
    "Respuesta completa", "Respuesta completa", "Respuesta parcial", 
    "Respuesta parcial", "Respuesta completa", "Respuesta completa", 
    "Respuesta completa")), row.names = c(NA, -9L), label = "File created by user 'asyncjobs_user' at Thu Mar  3 13:59:19 202", class = c("tbl_df", 
"tbl", "data.frame"))

我的ggplot:

graf_res<-
  res1 %>% 
  mutate(dia_de_respuesta = as.Date(dia_de_respuesta)) %>% 
  drop_na(dia_de_respuesta) %>% 
  group_by(dia_de_respuesta) %>% 
  count() %>% 
  ggplot()+
  #grafico respuestas
  geom_point(aes(x = dia_de_respuesta, y = n), stat = "identity", color = "#1b9e77", size = 3)+
  geom_text(aes(x = dia_de_respuesta, y = n, label = n), vjust = -0.3) +
  geom_line(aes(x = dia_de_respuesta, y = n), stat = "identity", linetype = "dashed", color = "gray40") + 
  scale_y_continuous(label = scales::label_number(accuracy = 1)) +
  #temas
  theme_pubclean() +
  labs(
    title = "Respuestas Maestría Docencia Universitaria PUCP\n por fecha",
    caption = "Fuente: Pulso PUCP"
  ) +
  xlab(label = "Día en que respondió la encuesta") +
  ylab(label = "Frecuencia (n)") +
  theme(plot.caption = element_text(face = "italic"))

我的 .Rmd 的 yaml 标头

---
title: "Reporte Maestría Docencia Universitaria"
date: "`r format(Sys.time(), '%d de %B de %Y')`"
output: 
  officedown::rdocx_document:
    plots:
      style: Normal
      align: center
      topcaption: true
      caption: 
        style: Image Caption
        pre: "Gráfico "
        sep: ": "
        tnd: 0
        tns: '-'
        fp_text: !expr officer::fp_text_lite(bold = TRUE)
    page_size:
      width: 8.3
      height: 11.7
      orient: "portrait"
    page_margins:
      bottom: 0.984252
      top: 0.984252
      right: 1.1811
      left: 1.1811
      header: 0.5
      footer: 0.5
      gutter: 0
    reference_num: true
knit: (
  function(inputFile, encoding) {
    rmarkdown::render(
      input = inputFile,
      encoding = encoding,
      output_file = glue::glue("reporte","_", format(Sys.Date(), '%d.%m.%y'),".docx" ))})

---

提前致谢!

4

0 回答 0