10

I would like to write some notes under my ggplot. I did my data analysis in R and using now the markdown package to write my thesis. This means I can easily include variables in the markdown script. In that script I create some ggplots and was wondering if there is an easy way to write those explanations to the plot. For tables, it is pretty straight forward. %>% footnote(general="") does the trick.

Is there something like that for plots?

user438383
  • 5,716
  • 8
  • 28
  • 43
severin
  • 111
  • 1
  • 1
  • 6
  • "I create my thesis in markdown" Does that mean you are using the rmarkdown package? Please indicate in your question (edit it). Your question seems to be about markdown and not about ggplot2. Please fix the tags. – Roland Jul 16 '19 at 07:39
  • The question is about `ggplot2`, not `rmarkdown`. He just provides an example for markdown for what he wants to accomplish. You can use `annotate()` – Claudiu Papasteri Jul 16 '19 at 07:51
  • @ClaudiuPapasteri I interpret "write some notes under my ggplot" and the reference to `footnote` differently. – Roland Jul 16 '19 at 07:58
  • Sorry, I was unclear. The reference to footnote, was an example of what I would like to achieve with my plot. @ClaudiuPapasteri if I'm not mistaken, with the annotate function you can write all over the plot. But I would like to write beneath it. Like a note for a figure in a paper... – severin Jul 16 '19 at 08:21
  • 1
    It's probably possible (and preferable) to do this with markdown ... – Roland Jul 16 '19 at 08:37

3 Answers3

19

Perhaps you are looking for something like this?

p <- ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() + labs(title = "Your title", caption = "Your long reference footnote goes in here")

You need to use the caption parameter from labs() function.

Example:

enter image description here

Ankur Sinha
  • 6,473
  • 7
  • 42
  • 73
3

Since you mentioned you are writing a thesis, I found the following helpful. You can insert a code chunk along the following lines:

    ```{r, fig.cap = "\\label{fig:myfigure} Here be your caption text"}
    generate_a_figue(my_data)
    ```

Then, in the main text of your markdown text you could refer to your figure as follows (Figure \ref{fig:myfigure})

teunbrand
  • 33,645
  • 4
  • 37
  • 63
0

Also you could left align or center align your caption by adding:

    ``` + theme(plot.caption=element_text(hjust = int)

For left align : hjust = 0
For center align: hjust = 0.5
For right align : hjust = 1
Zahra_fa
  • 11
  • 1