rmarkdown::render -- plots not showing

Hi All.

I'm new to R and just dipping my toes into programming in general, so please excuse any potentially huge gaps in knowledge/stupidity.

I've created a large 33mb Rmarkdown report which generates a number of graphs relating to organisational performance metrics at departmental-level. My current process has been to knit this file every morning, and then manually save the .html output in a network folder so it can be accessed by various interested users scattered across the company.

I want to ideally move toward automating this process, so my first step from some Googling was to do this:

rmarkdown::render( "C:/folder1/folder2/test.Rmd", output_format = "html_document", output_file = "test.html", output_dir = "Z:/folder3")

This appears to do what I want, as I no longer need to manually copy and paste/overwrite. However, when I open the file, I find that many of the plots generated from running the above aren't rendering -- (note: the issue doesn't occur when "knitting", only when running the above). Specifically, plots that are generated from the below loop function are not showing... more basic plots elsewhere in the Rmarkdown (without any of the looping logic) are showing just fine.

Is there anything obvious that I am missing? Thanks very much for any help.

for (Spec in UnSpec_SUR) {
Sel <- SES_SPE %>%
filter(Splty == Spec)

cat("###", Spec, "\n") 
x <- ggplot(Sel, aes(WeekStartDate, Used)) +
  geom_smooth(fill = "#C1E7FA") +
  geom_line(colour = '#595957') +
  geom_point(colour = '#F1055B', size = 2) +
  geom_vline(aes(xintercept = as.numeric(as.Date("2022-04-04")), 
                 colour = "Financial Year Start"), linetype = 4) +
  geom_hline(aes(yintercept = Sel$Allocation, colour = "Allocated"), linetype = 4) +
  geom_text(aes(label = round(Used,0)), vjust = -0.8, size = 3, colour = '#F1055B') +
  scale_x_date(date_breaks = "1 week",
               date_labels = "%d-%b") +
  scale_color_manual(name = "", values = c("Allocated" = "#EC950F", 
                                           'Financial Year Start' = "forestgreen" )) +
  theme_bw() +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1, size = 9),
        axis.title.x = element_text(size = 10),
        axis.text.y = element_text(vjust = 0.5, size = 9),
        axis.title.y = element_text(size =10),
        plot.title = element_text(size = 12, face ="bold"),
        legend.position = "bottom",
        legend.justification = "right",
        legend.text = element_text(size = 7),
        legend.margin=margin(t=-20)) +
  labs(title = Spec, x = 'Week Commencing', y = 'Used') 



You mean clicking the Knit button ?

Can you try running the same exact command in your R Console ? That means without changing output file name or output directory ?

This is possibly because of the fact that you are trying to generate Markdown content with computation content, all that from a chunk I believe. You need to use specific technics to make that robust. See about these here:

You are using print(x) in your code, but it may not be enough to correctly insert the plot code about your cat-ted content.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.