Overleaf Markdown



Code

  1. Overleaf Markdown Cheat
  2. Overleaf R Markdown
  3. Overleaf Insert Markdown
  4. Overleaf Markdown Table
  5. Overleaf Markdown Code
Overleaf Markdown

Otherwise, everything about the code chunks and chunk options is the same as with R Markdown. To produce LaTeX tables, you can use kable and xtable much as you would do with R Markdown. And the results look considerably nicer than the html tables. (You can’t use pander package within LaTeX.) Here’s a kable example.

  1. The typeset documentation will reside in the file markdown.pdf. Tutorials and example documents by Lian Tze Lim at Overleaf: How to write in Markdown on Overleaf, Markdown into LaTeX with Style, Writing Markdown in LaTeX Documents, Writing Beamer Slides with Markdown, Writing Posters with Markdown, and; Using Markdown in LaTeX documents.
  2. Point Engineering Limited The sheets attached overleaf contain brief description of some of the key projects previously executed by Point Engineering.
  3. Overleaf editor automatically inserts an inconvenient line break in the middle of a word or sentence after apostrophes and accents 0 How to add Latex packages to markdown?

One of the neat tools available via a variety of packages in R is the creation of beautiful tables using data frames stored in R. In what follows, I’ll discuss these different options using data on departing flights from Seattle and Portland in 2014. (More information and the source code for this R package is available at https://github.com/ismayc/pnwflights14.)

We begin by ensuring the needed packages are installed and then load them into our R session.

The dataset provides for the development of a lot of interesting questions. Here I will delve further into some of the questions I addressed in two recent workshops I led in the Fall 2015 Data @ Reed Research Skills Workshop Series. (Slides available at http://rpubs.com/cismay.)

Overleaf

The questions I will analyze by creating tables are

  1. Which destinations had the worst arrival delays (on average) from the two PNW airports?
  2. How does the maximum departure delay vary by month for each of the two airports?
  3. How many flights departed for each airline from each of the airports?

The kable function in the knitr package

To address the first question, we will use the dplyr package written by Hadley Wickham as below. We’ll use the top_n function to isolate the 5 worst mean arrival delays.

This information is helpful but you may not necessarily know to which airport each of these FAA airport codes refers. One of the other data sets included in the pnwflights14 package is airports that lists the names. Here we will do a match to identify the names of these airports using the inner_join function in dplyr.

Lastly we output this table cleanly using the kable function.

MarkdownMarkdown

Overleaf Markdown Cheat

Airport NameAirport CodeMean Arrival Delay
Cleveland Hopkins IntlCLE26.150000
William P HobbyHOU10.250000
Metropolitan Oakland IntlOAK10.067460
San Francisco IntlSFO8.864937
Bellingham IntlBLI8.673913

Oddly enough, flights to Cleveland (from PDX and SEA) had the worst arrival delays in 2014. Houston also had around a 10 minute delay on average. Surprisingly, the airport in Bellingham, WA (only around 100 miles north of SEA) had the fifth largest mean arrival delay.

The DT package

In order to answer the second question, we’ll again make use of the various functions in the dplyr package.

The DT package provides a nice interface for viewing data frames in R. I’ve specified a few extra options here to show all 12 months by default and to automatically set the width. Go ahead and play around with the filter boxes at the top of each column too. (An excellent tutorial on DT is available at https://rstudio.github.io/DT/.)

The created table in HTML is available here.

If you click on the max_delay column header, you should see that the maximum departure delay for PDX was in March and for Seattle was in May.

The xtable package to produce nice tables in a PDF

Again, we find ourselves using the extremely helpful dplyr package to answer this question and to create the underpinnings of our table to display. We merge the flights data with the airlines data to get the names of the airlines from the two letter carrier code.

The xtable package and its xtable function (and also the kable function you saw earlier) provide the functionality to generate HTML code or LaTeX code to produce a table. We will focus on producing the LaTeX code in this example.

Overleaf R Markdown

begin{table}[ht]
centering
begin{tabular}{rllrl}
hline
& origin & carrier & count & name
hline
1 & PDX & AS & 12844 & Alaska Airlines Inc.
2 & PDX & WN & 11193 & Southwest Airlines Co.
3 & PDX & OO & 9841 & SkyWest Airlines Inc.
4 & PDX & UA & 6061 & United Air Lines Inc.
5 & PDX & DL & 5168 & Delta Air Lines Inc.
6 & PDX & US & 2361 & US Airways Inc.
7 & PDX & AA & 2187 & American Airlines Inc.
8 & PDX & F9 & 1362 & Frontier Airlines Inc.
9 & PDX & B6 & 1287 & JetBlue Airways
10 & PDX & VX & 666 & Virgin America
11 & PDX & HA & 365 & Hawaiian Airlines Inc.
12 & SEA & AS & 49616 & Alaska Airlines Inc.
13 & SEA & WN & 12162 & Southwest Airlines Co.
14 & SEA & DL & 11548 & Delta Air Lines Inc.
15 & SEA & UA & 10610 & United Air Lines Inc.
16 & SEA & OO & 8869 & SkyWest Airlines Inc.
17 & SEA & AA & 5399 & American Airlines Inc.
18 & SEA & US & 3585 & US Airways Inc.
19 & SEA & VX & 2606 & Virgin America
20 & SEA & B6 & 2253 & JetBlue Airways
21 & SEA & F9 & 1336 & Frontier Airlines Inc.
22 & SEA & HA & 730 & Hawaiian Airlines Inc.
hline
end{tabular}
end{table}

Overleaf Insert Markdown

If you don’t know LaTeX, I’ve also duplicated a similar table using kable for you to compare:

origincarriercountname
PDXAS12844Alaska Airlines Inc.
PDXWN11193Southwest Airlines Co.
PDXOO9841SkyWest Airlines Inc.
PDXUA6061United Air Lines Inc.
PDXDL5168Delta Air Lines Inc.
PDXUS2361US Airways Inc.
PDXAA2187American Airlines Inc.
PDXF91362Frontier Airlines Inc.
PDXB61287JetBlue Airways
PDXVX666Virgin America
PDXHA365Hawaiian Airlines Inc.
SEAAS49616Alaska Airlines Inc.
SEAWN12162Southwest Airlines Co.
SEADL11548Delta Air Lines Inc.
SEAUA10610United Air Lines Inc.
SEAOO8869SkyWest Airlines Inc.
SEAAA5399American Airlines Inc.
SEAUS3585US Airways Inc.
SEAVX2606Virgin America
SEAB62253JetBlue Airways
SEAF91336Frontier Airlines Inc.
SEAHA730Hawaiian Airlines Inc.

With the originating airport duplicating across all of the airlines, it would be nice if we could reduce this duplication and just bold PDX or SEA and have each appear once. Awesomely enough, the rle function in R will be of great help to us in this endeavor. It counts how many times a value is repeated in a table. We will then make a call to the multirow function in LaTeX in a sneaky way of pasting the appropriate text in addition to using the force option for sanitizing the text into LaTeX.

We add in a few options to make the output of the table a little nicer by specifying horizontal lines and removing the default rownames.

The resulting table produced by LaTeX can be found at Overleaf.com at https://www.overleaf.com/read/wvrpxpwrbvnk.

Overleaf Markdown Table

We see that Alaska Airlines had the most flights out of both airports with Southwest coming in second at both airports.

Overleaf Markdown Code

(The generating R Markdown file for this HTML document—saved in the .Rmd extension—is available here.)