'problem with knitr, ggplot, scales, officedown, trouble in the axis
I'm having trouble knitting my ggplot in my .Rmd.
Brief summary: my input is an .Rmd and my output is word document through officedown.
My problem: my scale_y_continous looks good when i run my chunk (only integers no comma) but looks bad when i see it on my word doc (with decimals). Why this happen? i use scales::label_number(accuracy = 1) and it works in my chunk but when knitting it, it ignores this parameter.
In my r chunk .Rmd: (first image)

In my word doc: (second image)
my data:
> 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("[email protected]",
"[email protected]", "[email protected]",
"[email protected]", "[email protected]",
"[email protected]", "[email protected]",
"[email protected]", "[email protected]"), 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"))
my 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"))
my yaml header of my .Rmd
---
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" ))})
---
thanks in advance!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

