![]() ![]() To create a flexdashboard, we need to write an R Markdown file with extension. Tinytex::install_tinytex() ( Xie, Dervieux, and Riederer 2022).Īlternatively, LaTeX can be installed using the resources in the website.Īn R Markdown document includes three basic components, namely, a YAML header, Markdown text, and R code chunks.Īt the beginning of the document, we writeĪ YAML header surrounded by - that indicates several options such as title, author, date, and type of output file.įIGURE A.6: Screenshot of a flexdashboard to visualize air pollution data globally. The LaTeX distribution TinyTeX can be installed with the tinytex package ( Xie 2022) with Note that LaTeX is needed to generate PDF documents. Rmd file, and "output_document" the type of output (e.g., "html_document", "pdf_document"). Rmd file, a report can be generated using the Knit button in RStudio or executing rmarkdown::render("name.Rmd", "output_document"), where name.Rmd is the name of the. Rmd) can be created by clicking File > New File > R Markdown in RStudio.įrom the. Resources to learn R Markdown include Xie, Dervieux, and Riederer ( 2022), Xie, Allaire, and Grolemund ( 2018), and chapter 11 of Moraga ( 2019) which provides a reproducible example of how to create an R Markdown document that includes an exploratory data analysis with tables and visualizations.Ī new R Markdown document (. When the R Markdown document is compiled, the R code is executed and a report with the output of the R code is created. Rmd that intermingles text and R code,Īnd can include narrative text, tables, and visualizations. 2022) allows us to easily turn our analyses into fully reproducible documents that can be shared with others in a variety of formats including HTML and PDF.Īn R Markdown document is a text file with extension. Here, we use the st_read() function of sf to read the shapefile that contains the number of sudden infant deaths in North Carolina, USA, in 1974, and create a map using ggplot2 (Figure A.2). We can also add color scales (e.g., scale_colour_brewer(), faceting specifications (e.g., facet_wrap()), and coordinate systems (e.g., coord_flip()). For example, we add objects to the graph with geom_*() functions (e.g., geom_point() for points, geom_line() for lines). ![]() Layers consist of geoms, stats, scales, coords, facets, and themes. Then, we use the + symbol to add layers of graphical components to the graph. To create a plot with ggplot2, we call ggplot() specifying the data frame with the variables to plot ( data), and the aesthetic mappings between variables in the data and visual properties of the objects in the graph, such as the position and color of points or lines ( mapping = aes()). ![]() 2022) uses a grammar of graphics which defines the rules of structuring mathematic and aesthetic elements to build graphs layer-by-layer. The ggplot2 package ( Wickham, Chang, et al. This pane may also contain Git options for version control.įinally, the Files/Plots/Packages/Help pane (bottom-right) allows us to see the files in our working directory, the graphs generated, as well as packages and help pages. The Environment/History pane (top-right)Ĭontains tabs with datasets, variables, and other R objects, as well as the history of the previous R commands executed. To interact with R, we can type commands in the console or write code in script files in the code editor and copy-paste commands to the console. In the console pane (bottom-left), we see the execution and the output of the R code. In the code editor pane (top-left), we create and view the R script files. ![]() The RStudio IDE has typically four panes (Figure A.1). RStudio includes a console, a syntax-highlighting editor for writing and editing R code,Īnd a variety of tools for data visualization, debugging, and management of files and R projects. R can be run using the integrated development environment (IDE) called RStudio which can be freely downloaded from. R can be downloaded and installed from CRAN (Comprehensive R Archive Network). R is a free and open-source software environment for statistical computing and graphics that provides many excellent packages for importing and manipulating data, statistical analysis, and visualization. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |