Markdown is a blessing for whoever had to prepare a draft or a report. Of course, you must learn its use, but with some effort this is something anyone can master, provided has some programming experience.
Markdown, and its implementation in RStudio can be used for many things, since a file in markdown can be converted in LaTeX, .pdf and html, among others.
You can even prepare an entire book in markdown, with professional output.
So, you may be interested in knowing how to add an image to markdown.
Very simple, indeed.
First think first: you must have your image in .jpg or .png
The best way is to group all images in a folder, to be put in a directory, the directory to which RStudio has access.
To add an image in markdown you must stop text editing, and you do this with the command [Alt text] precedeed by a !
Then you have to add the path to the image in brackets.
The path to the image is the path from your directory to the image.
Therefore, if the directory is C:/Users/Antonio/Documents and the image is in the folder named images and the name of the image is tufte.book.jpg (the name always with the extension), then your path is
/Users/Antonio/Documents/images/tufte.book.jpg
As you can see, no source of the path (C:): delete it!
Repetita iuvant: the path is YourDirectory/the_folder/name_of_the_image_with_its_extension (.jpg or .png or whatever)
Let’s see what happen with this command: ! [Alt text] (/Users/Antonio/Documents/images/tufte.book.jpg)
The image is loaded in the markdown file, and we can see it. Good.
You can also print two paired images, by simply placing the commands side by side, like this
! [Alt text] (/Users/Antonio/Documents/images/tufte.book.jpg) ! [Alt text] (/Users/Antonio/Documents/images/Tufte.png)
Depending on the size of the images, you can have three, four, who may say?, paired images in your file. For example, let’s see two Tufte’ s famous books on data visualization and the Charles Joseph Minard’s chart, a now well-known graphic showing the losses of the French Army in Napoleon’ s Russian campaign. Tufte contributed to draw attention to this chart, which, according to him, summarizes his six principles of analytical design:
It is helpful to have the opportunity of loading images in markdown, because sometime you have plots or graphs that cannot be plotted properly by RStudio, whatever you try. So, save the plot as .jpg or .png or .tiff, then load it into your markdown file.
Here a gallery:
One
Two
Three
Four
All these images are based on codes I’ve found in Internet. Unfortunately, I do not remember from where I’ve got the code, so I cannot give the proper credit: sorry for that!…:-)
I still do not know how to modify the size of an image in markdown. I resize manually the image with a dedicated program (not a great solution, I admit).
How did I change the default color in the lines? I used this command <span style=“color:red”> before the word or phrase and </span> after the word or phrase.
For example, <span style=“color:green”> Victory shall be mine </span> will produce this:
Victory shall be mine
You may use any color you want, provided it is a color that is allowed by RStudio.
I hope you’ve enjoyed this!
Have a nice day!