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?
You can use the annotate() function to add text to plots in ggplot2. where: x, y: The (x, y) coordinates where the text should be placed. label: The text to display.
If you want to annotate your plot or figure with labels, there are two basic options: text() will allow you to add labels to the plot region, and mtext() will allow you to add labels to the margins. For the plot region, to add labels you need to specify the coordinates and the label.
%>% is a pipe operator reexported from the magrittr package. Start by reading the vignette. Adding things to a ggplot changes the object that gets created. The print method of ggplot draws an appropriate plot depending upon the contents of the variable.
The function geom_point() adds a layer of points to your plot, which creates a scatterplot. ggplot2 comes with many geom functions that each add a different type of layer to a plot.
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:
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})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With