Go to TogaWare.com Home Page. Data Science Desktop Survival Guide
by Graham Williams
Duck Duck Go



CLICK HERE TO VISIT THE UPDATED SURVIVAL GUIDE

Adding a Caption and Reference Label

Raw We have seen captions and labels above but tell the story here in a slightly different way.

print(xtable(ds,
             digits=0,
             caption="Selected observations from \\textbf{weatherAUS}."),
      include.rownames=FALSE)


Table: Selected observations from weatherAUS.
Location MinTemp MaxTemp Rainfall Evaporation
Tuggeranong 10 25 0  
Wollongong 21 31 1  
Dartmoor 6 15 2 3
Sale 17 29 0 6
WaggaWagga 8 31 0 4


Notice that we wanted to emphasise the name of the dataset in the caption. We can make it bold using the \textbf{} command of LaTeX within the string passed to caption=. We need to repeat the backslash because R itself will attempt to interpret it otherwise. That is, we escape the backslash.

As well as adding a caption with a table number, we can add a label to the xtable::xtable() command and then refer to the table within the text using the \ref{MyTable} LaTeX command. Thus, in the source document we use “Table~\ref{MyTable}” to produce “Table [*]” in the documnet.

print(xtable(ds,
             digits=0,
             caption="Selected observations from \\textbf{weatherAUS}.",
             label="MyTable"),
      include.rownames=FALSE)


Table: Selected observations from weatherAUS.
Location MinTemp MaxTemp Rainfall Evaporation
Tuggeranong 10 25 0  
Wollongong 21 31 1  
Dartmoor 6 15 2 3
Sale 17 29 0 6
WaggaWagga 8 31 0 4


The references to Table [*] can appear anywhere in the document. We can even refer to its page number by replacing \ref{MyTable} with \pageref{MyTable} to get Table [*] on Page [*].


Support further development by purchasing the PDF version of the book.
Other online resources include the GNU/Linux Desktop Survival Guide.
Books available on Amazon include Data Mining with Rattle and Essentials of Data Science.
Popular open source software includes rattle and wajig.
Hosted by Togaware, a pioneer of free and open source software since 1984.
Copyright © 2000-2020 Togaware Pty Ltd. . Creative Commons ShareAlike V4.