UM-R-for-EnvSci-Registered-Student / General-Discussion

Public repo for general discussion about the course and assignments
1 stars 0 forks source link

Figures not showing in the .md output file on GitHub #4

Open peperg opened 4 years ago

peperg commented 4 years ago

Hello!

A lot of you have bene having a very similar issue with the week 5 assignment.

Most of you have the code in he .Rmd working fine, but then when you go on GitHub it does not show the figures.

I am quite confident i have the answer to why that is happening for ~90% of you.

As i noted in the "hints" of the assignment instructions, i recommended that you created a new folder called rmarkdown.

Many of you have created the .Rmd file in the general root folder of the R project. Some of you, started that way and then moved some of the outputs to the 'rmarkdown` folder afterwards.

That doesn't quite work... The .Rmd file needs to be in its own folder (the rmarkdown folder) before you press knit.

That is because, as i mentioned, when the .Rmd file gets knit, a lot of things happen. It creates the .md and .html outputs, and it also creates its own folder of images. These are independent of the figures you had to output as part of the assignment, and these are the ones that get displayed in the .md and .html files.

In order to make sure everything gets created in the proper place, contained in the proper place, and read properly later on, the .Rmd file needs to be in its own folder (the rmarkdown) folder before you knit.

What i suggest for all those of you who are having trouble with the figures not showing in the .md file on GitHub:

  1. delete the .md and .html outputs as well as their associated figure folder (it is called figure-html).
  2. create the rmarkdown folder if you don't have one
  3. make sure your .Rmd is inside of the rmarkdown folder
  4. open the .Rmd file and hit knit again

Now all outputs should be created inside of the rmarkdown folder and the images should show properly in the outputs

peperg commented 4 years ago

Update on this issue.

Today it was pointed out to me that some of my figures were actually not showing in the Week 06 - class materials repo. That made me look at my figures and try to see what made some of my figures different from others.

The ones tat were not showing had spaces in the name of the chunk. like this:

```{r stacked bars}

argentina_clean %>% 
  filter(season == "2") %>% 
  ggplot() +
  geom_col(aes(x = site, y = counts, fill = species))

During the knitting R creates that small folder of figures to be used in the .html and .md files. It uses the name of the chunk they come from as the figure name. In the computer there is no issue, but it seems that the GitHub internals don't like spaces in filenames, so it wasn't able to link to those figures when trying to display it.

If you use underscores instead of spaces as chunk names (and with that for the names of the internal figures) then it manages to link! like this:

```{r stacked_bars}

argentina_clean %>% 
  filter(season == "2") %>% 
  ggplot() +
  geom_col(aes(x = site, y = counts, fill = species))

This might have been the issue some of you were having. The good news is that it wasn't technically an R issue, but a GitHub issue. But at least now we know!