├── .Rbuildignore ├── .Renviron ├── .Rprofile ├── .github └── workflows │ └── r-check.yml ├── .gitignore ├── .vscode └── tasks.json ├── DESCRIPTION ├── NAMESPACE ├── NEWS.md ├── R ├── RcppExports.R ├── fplot.R ├── miscfuns.R ├── onload.R ├── visualization.R └── xaxis.R ├── Readme.md ├── data ├── datalist └── us_pub_econ.RData ├── docs ├── 404.html ├── articles │ ├── Exporting_graphs.html │ ├── export_example_10pt.png │ ├── export_example_12pt.png │ ├── fplot_walkthrough.html │ ├── fplot_walkthrough_files │ │ └── figure-html │ │ │ ├── unnamed-chunk-10-1.png │ │ │ ├── unnamed-chunk-14-1.png │ │ │ ├── unnamed-chunk-16-1.png │ │ │ ├── unnamed-chunk-17-1.png │ │ │ ├── unnamed-chunk-18-1.png │ │ │ ├── unnamed-chunk-19-1.png │ │ │ ├── unnamed-chunk-20-1.png │ │ │ ├── unnamed-chunk-21-1.png │ │ │ ├── unnamed-chunk-22-1.png │ │ │ ├── unnamed-chunk-23-1.png │ │ │ ├── unnamed-chunk-24-1.png │ │ │ ├── unnamed-chunk-25-1.png │ │ │ ├── unnamed-chunk-26-1.png │ │ │ ├── unnamed-chunk-27-1.png │ │ │ ├── unnamed-chunk-28-1.png │ │ │ ├── unnamed-chunk-29-1.png │ │ │ ├── unnamed-chunk-5-1.png │ │ │ ├── unnamed-chunk-6-1.png │ │ │ ├── unnamed-chunk-7-1.png │ │ │ ├── unnamed-chunk-8-1.png │ │ │ └── unnamed-chunk-9-1.png │ ├── images │ │ ├── export │ │ │ ├── example_10pt.png │ │ │ ├── example_12pt.png │ │ │ ├── example_12pt_sideways.png │ │ │ └── example_12pt_tall.png │ │ ├── export_example_10pt.png │ │ ├── export_example_12pt.png │ │ ├── export_example_12pt_sideways.png │ │ └── export_example_12pt_tall.png │ └── index.html ├── authors.html ├── bootstrap-toc.css ├── bootstrap-toc.js ├── docsearch.css ├── docsearch.js ├── index.html ├── link.svg ├── news │ └── index.html ├── pkgdown.css ├── pkgdown.js ├── pkgdown.yml ├── reference │ ├── Rplot001.png │ ├── Rplot002.png │ ├── Rplot003.png │ ├── Rplot004.png │ ├── Rplot005.png │ ├── Rplot006.png │ ├── Rplot007.png │ ├── Rplot008.png │ ├── Rplot009.png │ ├── Rplot010.png │ ├── Rplot011.png │ ├── export_graph_start-1.png │ ├── export_graph_start.html │ ├── figures │ │ ├── conditional_iris_1.png │ │ ├── conditional_iris_2.png │ │ ├── conditional_iris_3.png │ │ ├── conditional_pub_1.png │ │ ├── conditional_pub_2.png │ │ ├── conditional_pub_3_bis.png │ │ ├── conditional_trade_1.png │ │ ├── conditional_trade_2.png │ │ ├── cumul_iris.png │ │ ├── cumul_pub.png │ │ ├── cumul_trade.png │ │ ├── export │ │ │ ├── example_10pt.png │ │ │ ├── example_12pt.png │ │ │ ├── example_12pt_sideways.png │ │ │ └── example_12pt_tall.png │ │ ├── regular_iris.png │ │ ├── regular_pub.png │ │ ├── regular_trade.png │ │ ├── weighted_conditional_trade_1.png │ │ ├── weighted_conditional_trade_2.png │ │ ├── weighted_pub_1.png │ │ ├── weighted_pub_2.png │ │ ├── weighted_stacked_pub.png │ │ ├── weighted_stacked_trade.png │ │ ├── weighted_trade_1.png │ │ └── weighted_trade_2.png │ ├── fit.off.html │ ├── fplot-package.html │ ├── index.html │ ├── pdf_fit.html │ ├── plot_box-1.png │ ├── plot_box-2.png │ ├── plot_box-3.png │ ├── plot_box-4.png │ ├── plot_box-5.png │ ├── plot_box.html │ ├── plot_distr-1.png │ ├── plot_distr-2.png │ ├── plot_distr-3.png │ ├── plot_distr-4.png │ ├── plot_distr-5.png │ ├── plot_distr-6.png │ ├── plot_distr-7.png │ ├── plot_distr-8.png │ ├── plot_distr-9.png │ ├── plot_distr.html │ ├── plot_lines-1.png │ ├── plot_lines-2.png │ ├── plot_lines-3.png │ ├── plot_lines.html │ ├── png_fit.html │ ├── setFplot_dict-1.png │ ├── setFplot_dict.html │ ├── setFplot_distr-1.png │ ├── setFplot_distr-2.png │ ├── setFplot_distr.html │ ├── setFplot_page.html │ └── us_pub_econ.html └── sitemap.xml ├── fplot.Rproj ├── man ├── export_graph_start.Rd ├── figures │ ├── conditional_iris_1.png │ ├── conditional_iris_2.png │ ├── conditional_iris_3.png │ ├── conditional_pub_1.png │ ├── conditional_pub_2.png │ ├── conditional_pub_3_bis.png │ ├── conditional_trade_1.png │ ├── conditional_trade_2.png │ ├── cumul_iris.png │ ├── cumul_pub.png │ ├── cumul_trade.png │ ├── regular_iris.png │ ├── regular_pub.png │ ├── regular_trade.png │ ├── weighted_conditional_trade_1.png │ ├── weighted_conditional_trade_2.png │ ├── weighted_pub_1.png │ ├── weighted_pub_2.png │ ├── weighted_stacked_pub.png │ ├── weighted_stacked_trade.png │ ├── weighted_trade_1.png │ └── weighted_trade_2.png ├── fit.off.Rd ├── fplot-package.Rd ├── pdf_fit.Rd ├── plot_box.Rd ├── plot_distr.Rd ├── plot_lines.Rd ├── png_fit.Rd ├── setFplot_dict.Rd ├── setFplot_distr.Rd ├── setFplot_page.Rd └── us_pub_econ.Rd ├── src ├── Makevars ├── Makevars.win ├── RcppExports.cpp ├── misc_funs.cpp └── string_truncation.cpp └── vignettes ├── Exporting_graphs.Rmd ├── fplot_walkthrough.Rmd └── images ├── conditional_iris_1.png ├── conditional_iris_2.png ├── conditional_iris_3.png ├── conditional_pub_1.png ├── conditional_pub_2.png ├── conditional_pub_3_bis.png ├── conditional_trade_1.png ├── conditional_trade_2.png ├── cumul_iris.png ├── cumul_pub.png ├── cumul_trade.png ├── export_example_10pt.png ├── export_example_12pt.png ├── export_example_12pt_sideways.png ├── export_example_12pt_tall.png ├── regular_iris.png ├── regular_pub.png ├── regular_trade.png ├── weighted_conditional_trade_1.png ├── weighted_conditional_trade_2.png ├── weighted_pub_1.png ├── weighted_pub_2.png ├── weighted_stacked_pub.png ├── weighted_stacked_trade.png ├── weighted_trade_1.png └── weighted_trade_2.png /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | vignettes/fplot_walkthrough.Rmd 4 | ^.github$ 5 | ^\.Renviron$ 6 | ^docs$ 7 | ^\.vscode$ 8 | -------------------------------------------------------------------------------- /.Renviron: -------------------------------------------------------------------------------- 1 | 2 | package_ROOT = TRUE 3 | 4 | -------------------------------------------------------------------------------- /.Rprofile: -------------------------------------------------------------------------------- 1 | 2 | 3 | # taken from: https://github.com/REditorSupport/vscode-R/wiki/Interacting-with-R-terminals 4 | if (interactive() && Sys.getenv("RSTUDIO") == "") { 5 | Sys.setenv(TERM_PROGRAM = "vscode") 6 | source(file.path(Sys.getenv( 7 | if (.Platform$OS.type == "windows") "USERPROFILE" else "HOME" 8 | ), ".vscode-R", "init.R")) 9 | 10 | options(vsc.rstudioapi = TRUE) 11 | } 12 | 13 | 14 | -------------------------------------------------------------------------------- /.github/workflows/r-check.yml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | branches: [main, master] 8 | 9 | name: R-CMD-check 10 | 11 | jobs: 12 | R-CMD-check: 13 | runs-on: ${{ matrix.config.os }} 14 | 15 | name: ${{ matrix.config.os }} (${{ matrix.config.r }}) 16 | 17 | strategy: 18 | fail-fast: false 19 | matrix: 20 | config: 21 | - {os: macos-latest, r: 'release'} 22 | - {os: windows-latest, r: 'release'} 23 | - {os: ubuntu-latest, r: 'release'} 24 | 25 | env: 26 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 27 | R_KEEP_PKG_SOURCE: yes 28 | 29 | steps: 30 | - uses: actions/checkout@v3 31 | 32 | - uses: r-lib/actions/setup-pandoc@v2 33 | 34 | - uses: r-lib/actions/setup-r@v2 35 | with: 36 | r-version: ${{ matrix.config.r }} 37 | http-user-agent: ${{ matrix.config.http-user-agent }} 38 | use-public-rspm: true 39 | 40 | - uses: r-lib/actions/setup-r-dependencies@v2 41 | with: 42 | extra-packages: any::rcmdcheck 43 | needs: check 44 | 45 | - uses: r-lib/actions/check-r-package@v2 46 | with: 47 | upload-snapshots: true 48 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Ruserdata 5 | src/*.o 6 | src/*.so 7 | src/*.dll 8 | src-i386/ 9 | src-x64/ 10 | *.Rproj 11 | .Rproj 12 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | 2 | { 3 | // This task has been automatically generated by 4 | // {$userHome}/.vscode/scripts/setup-r-projects 5 | // 6 | // When the VSCode folder is open, this task opens a split terminal 7 | // with git bash on the left and R terminal on the right 8 | // 9 | // This task is automatically added to the project only if an R folder is there 10 | // or the workspace root contains an .R file, or at least one direct childern folder 11 | // contains an .R file 12 | // 13 | // See ctrl+shift+P -> Tasks: Open user tasks -> "Setup R projects watcher" 14 | // 15 | 16 | "version": "2.0.0", 17 | "tasks": [ 18 | { 19 | "label": "Create terminals", 20 | // => will call these two tasks 21 | "dependsOn": [ 22 | "git bash", 23 | "R-term" 24 | ], 25 | // => starts the task when opening VSCode 26 | "runOptions": { 27 | "runOn": "folderOpen" 28 | } 29 | }, 30 | { 31 | "label": "git bash", 32 | "type": "shell", 33 | "command": "", 34 | "options": { 35 | "shell": { 36 | // NOTA: path/to/git/bin must be on PATH 37 | "executable": "sh.exe", 38 | "args": ["--login"] 39 | } 40 | }, 41 | // Mark as a background task to avoid the spinner animation on the terminal tab 42 | "isBackground": true, 43 | "problemMatcher": [], 44 | // Create the tasks in a terminal group 45 | "presentation": { 46 | "echo": false, 47 | "group": "my-group" 48 | } 49 | }, 50 | { 51 | "label": "R-term", 52 | "type": "shell", 53 | "command": "", 54 | "options": { 55 | "shell": { 56 | // NOTA: to attach R properly to VSCode, you need the custom .Rprofile 57 | // that is why you should have an Rprofile set up properly 58 | // see task "Write VSCode Rprofile" 59 | "executable": "radian.exe", 60 | "args": ["--no-save", "no-restore"] 61 | } 62 | }, 63 | "isBackground": true, 64 | "problemMatcher": [], 65 | "presentation": { 66 | "echo": false, 67 | "group": "my-group" 68 | } 69 | } 70 | ] 71 | } 72 | 73 | 74 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: fplot 2 | Type: Package 3 | Title: Automatic Distribution Graphs Using Formulas 4 | Version: 1.1.0 5 | Authors@R: person("Laurent", "Berge", email = "laurent.berge@u-bordeaux.fr", role = c("aut", "cre")) 6 | Imports: stats, graphics, utils, Formula, Rcpp, grDevices, dreamerr(>= 1.1.0) 7 | Suggests: knitr, rmarkdown, fixest, pdftools 8 | LinkingTo: Rcpp 9 | Depends: R(>= 3.5.0), data.table 10 | Description: Easy way to plot regular/weighted/conditional distributions by using formulas. The core of the package concerns distribution plots which are automatic: the many options are tailored to the data at hand to offer the nicest and most meaningful graphs possible -- with no/minimum user input. Further provide functions to plot conditional trends and box plots. See for more information. 11 | License: GPL-3 12 | VignetteBuilder: knitr 13 | Encoding: UTF-8 14 | LazyData: true 15 | RoxygenNote: 7.2.3 16 | Roxygen: list(markdown = TRUE) 17 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | useDynLib(fplot, .registration = TRUE) 2 | 3 | 4 | # Main plotting functions 5 | export(plot_distr, plot_lines, plot_box) 6 | 7 | # Export figures 8 | export(pdf_fit, png_fit, bmp_fit, tiff_fit, jpeg_fit, fit.off) 9 | export(export_graph_start, export_graph_end) 10 | 11 | # setters & getters 12 | exportPattern("^(s|g)etFplot") 13 | 14 | 15 | 16 | # IMPORTS 17 | 18 | import(data.table) 19 | import(Rcpp) 20 | import(dreamerr) 21 | 22 | importFrom("graphics", "abline", "axis", "barplot", "box", "grid", 23 | "legend", "lines", "par", "plot", "points", "polygon", 24 | "rect", "segments", "strheight", "strwidth", "text", 25 | "title") 26 | importFrom("stats", "lm", "median", "quantile", "sd", "formula", "na.omit", "var", "as.formula", "terms", "update") 27 | importFrom("utils", "head", "tail") 28 | importFrom("Formula", "Formula") 29 | importFrom("grDevices", "pdf", "png", "jpeg", "bmp", "tiff", "dev.off") 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | 2 | # fplot 1.1.0 3 | 4 | ## New functions 5 | 6 | - new pair of functions `export_graph_start` and `export_graph_end` to export graphs. This is similar to the family of functions `pdf_fit`, `png_fit`, etc, and `fit.off()`, but possibly more intuitive. 7 | 8 | ## Bug fixes 9 | 10 | - Bug in `plot_box` when a call of the form `plot_box(var ~ 1, base)` was used. 11 | - Bug in `plot_box` when a call of the form `plot_box(. ~ 1, base)` was used. 12 | 13 | ## Other 14 | 15 | - update the maintainer's email address 16 | - remove warning from `pdftools::pdf_convert` popping when exporting graphs. 17 | - when exporting graphs, there is a preview of the exported graph. Now the image is embedded in the HTML file via URI to avoid file path issues (this led to a bug in the VSCode viewer). 18 | - the documentation is updated to add clear guidance for `ggplot2` graph exportation 19 | - improved documentation 20 | 21 | # fplot 1.0.0 (2020-05-08) 22 | 23 | ## New set of functions to export graphs 24 | 25 | - A new set of functions has been created to easily export figures that should fit in a document. 26 | 27 | - The five functions are `pdf_fit`, `png_fit`, `jpeg_fit`, `tiff_fit` and `bmp_fit`. 28 | 29 | - First, if needed, you set the geometry of your document with `setFplot_page`. Defaults to US-letter and *normal* margins => this is used to deduce the size the figures will take in the document. 30 | 31 | - When using `pdf_fit`, instead of providing the height and width of the figure in absolute terms, you provide the fraction of the text-width the figure should take, and the target font-size at which the plotting text should be rendered. The size of the plotting text, once the figure is in the final document, is guaranteed. 32 | 33 | - Use `fit.off` instead of `dev.off` to close the device and you will get the exported graph displayed in the viewer pane! No need to open your file to see whether the export is proper, you have it automatically done! 34 | 35 | ## New function: setting default values for `plot_distr` 36 | 37 | - New function `setFplot_distr` to set most default values of the function `plot_distr`. 38 | 39 | ## User visible changes in `plot_distr` 40 | 41 | - MAJOR CHANGE NOT RETRO COMPATIBLE: complete overhaul of the formula. Now the main argument 'fml' is of the form `weights ~ var | moderator` (before it was `var ~ moderator | weights`). Allows to use one-sided formulas. 42 | - Argument `tick_5` becomes `at_5` and can take three values: FALSE, "roman" or "line". It is used to inform on the index of the bars by adding a small Roman number under every 5 bars (`at_5 = "roman"`), or drawing a thick axis line every 5 bars (`at_5 = "line"`). The default depends on the types of the data. 43 | - When fractions are displayed on top of the bars, very low numbers are now trucated (avoids having to display too small numbers). 44 | 45 | - The name of the moderator is now displayed in the yaxis when appropriate for within distributions. 46 | - Legend titles are now always displayed by default. 47 | - You can display the distribution for several weights at the same time. 48 | - Argument `mod.method` has been revamped. It's meaning has been split: `mod.method` takes values in "side", "split" or "stack" and two new arguments `within` and `total` have been created to define whether the distribution should be within each moderator or over the total distribution. 49 | - The argument `trunc.method` now takes the values "auto", "right" and "mid" (instead of "auto", "trimRight" and "trimMid"). 50 | - The size of the bottom and left margins are now automatically adjusted so the text always fit. 51 | - Argument `mod.select` now supports regular expressions. 52 | - New argument `mod.NA` which display the distribution of missing values. 53 | 54 | ## User visible changes in `plot_lines` 55 | 56 | - You can display the trend for several variables at the same time => they will be treated as moderators. 57 | - One sided formulas are accepted. 58 | - Argument `mod.select` now supports regular expressions. 59 | - New argument `mod.NA` which display the distribution of missing values. 60 | 61 | ## User visible changes in `plot_box` 62 | 63 | - You can display several variables at once (long overdue!). 64 | 65 | ## Error-handling 66 | 67 | - Better error-handling with dreamerr's functions. 68 | 69 | ## Bug correction 70 | 71 | - plot_lines: Bug when plotting frequencies with moderators. 72 | - plot_box: Bug regarding the display of the outliers when the cases are of type factor. 73 | - plot_distr: Bug when the variable was of type logical. 74 | - fplot: Bug when the moderator was loigical. 75 | 76 | 77 | ## Arguments: name change 78 | 79 | - max_line => line.max 80 | - tick_5 => at_5 (and is much better implemented) 81 | - maxFirst => sorted 82 | - onTop => top 83 | - addOther => other 84 | - maxBins => nbins 85 | - toLog => log 86 | 87 | # Changes in version 0.2.1 (2020-02-12) 88 | 89 | ## User visible changes 90 | 91 | - Better adjustment of the legend height. 92 | 93 | ## Bug fixes 94 | 95 | - plot_distr: Bug when the weight contained NAs. Now fixed. 96 | 97 | ## Other 98 | 99 | - Package `fixest` is removed from help files and called conditionnaly in the vignette. 100 | 101 | # Changes in version 0.2.0 (2019-11-21) 102 | 103 | ## Major improvements 104 | 105 | - plot_distr: A new method for displaying moderators: mod.method = "stack". 106 | - plot_distr: A new argument "cumul" to represent cumulative distributions. 107 | - `mod.method = "splitXX"` is now supported with logarithmic data 108 | - `mod.method = "splitXX"` + `toLog=TRUE`: now supports the "other" column. 109 | - `labels.tilted=TRUE` now possible with logarithmic data. 110 | 111 | ## Other improvements to plot_distr 112 | 113 | - when onTop != "none", very small numbers are not displayed any more (could lead to cluttering). 114 | - when onTop can also be equal to FALSE. 115 | - Now discrete ticks appear when plotting categorical data. They appear every 5/10 bins, in order to help counting the bins. 116 | - better labeling of the y-axis when `yaxis.num = TRUE`. 117 | - better automatic finding of the number of bins when argument bin was not missing. 118 | - better algorithm to find the default bin.size. 119 | - when bin.size is given, toLog's default is automatically set off. 120 | 121 | ## Improvements to plot_lines 122 | 123 | - Argument mod.select introduced to easily select moderator cases. 124 | - When smoothing_window > 1, supplemental years are removed. 125 | 126 | ## Data sets 127 | 128 | - Data on US publications in biology is removed. 129 | - Data on US publications in economics is added (much lighter than biology publications). 130 | 131 | 132 | ## Bug correction 133 | 134 | - `yaxis.num = TRUE` in the presence of moderators could cause problems in special cases. 135 | - Display problem when `mod.method = "splitxx"` and factor variables. 136 | - Display problem when `mod.method = "sidexx"` and with the other columns (problem in the bar cutting). 137 | - plot_distr: with moderators and mod.method = "sideWithin": rare bug corrected (identical values could be considered different). 138 | 139 | ## Relabeling of arguments 140 | 141 | - Argument `bin` becomes `bin.size`. 142 | - in argument `mod.method`, the value `within` and `total` become `sideWithin` and `sideTotal`. 143 | 144 | 145 | # Changes in version 0.1.0 (2019-11-01) 146 | 147 | ## First version! 148 | 149 | - This package is an effort to provide a simple class of plotting functions which: i) perform common operations in exploratory analyses, ii) have a compact syntax thanks to formulas, allowing aggregate/conditional/weighted graphs with minimum effort, iii) provide automatic options setting to best fit the data, iv) have a nice looking layout, and v) always take advantage of the full plotting region (without changing the graphical parameters) to export beautiful graphs with no/minimum tweak. 150 | -------------------------------------------------------------------------------- /R/RcppExports.R: -------------------------------------------------------------------------------- 1 | # Generated by using Rcpp::compileAttributes() -> do not edit by hand 2 | # Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 3 | 4 | cpp_unclassFactor <- function(x) { 5 | .Call(`_fplot_cpp_unclassFactor`, x) 6 | } 7 | 8 | cpp_unik <- function(x_sorted, k_max) { 9 | .Call(`_fplot_cpp_unik`, x_sorted, k_max) 10 | } 11 | 12 | cpp_string_shorten <- function(x, max_size = 15L) { 13 | .Call(`_fplot_cpp_string_shorten`, x, max_size) 14 | } 15 | 16 | -------------------------------------------------------------------------------- /R/fplot.R: -------------------------------------------------------------------------------- 1 | #' Aggregate/conditional graphs and automatic layout using formulas 2 | #' 3 | #' \pkg{fplot} provides automatic plotting of common graphs (distributions, lines, bar plots and boxplots). The syntax uses formulas, allowing aggregate/conditional/weighted graphs with minimum efforts. The many arguments are automatically adjusted to the data in order to provide the nicest and most meaningful graphs. 4 | #' 5 | #' @details 6 | #' 7 | #' The core functions is \code{\link[fplot]{plot_distr}} to draw distributions. 8 | #' Two other graphical functions are provided for convenience: \code{\link[fplot]{plot_lines}} to represent the (usually temporal) evolution of some variables, and \code{\link[fplot]{plot_box}} to easily represent conditional boxplots. 9 | #' 10 | #' It also integrates tools to easily export graphs: \code{\link[fplot]{pdf_fit}} and \code{\link[fplot]{png_fit}}. In these functions, instead of providing the size of the graphics, you instead give the point size that the text should have in the final document--because an exported graph usually ends up in a document. You can set the size of your document with the function \code{\link[fplot]{setFplot_page}}. If you use the function \code{\link[fplot]{fit.off}} to close the connection, you will also see how the export looks like in the Viewer pane. 11 | #' 12 | #' 13 | #' 14 | "_PACKAGE" 15 | -------------------------------------------------------------------------------- /R/onload.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | .onLoad = function(libname, pkgname){ 6 | 7 | # To circumvent a peculiar behavior from pkgdown 8 | fix_pkgwdown_path() 9 | 10 | if(is_r_check()){ 11 | data.table::setDTthreads(1) 12 | } 13 | 14 | invisible() 15 | } 16 | 17 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # fplot: distribution graphs the easy way 2 | 3 | Version 4 | Downloads 5 | 6 | `fplot` is an `R` package made for the easy plotting of distributions. 7 | 8 | The problem when it comes to distributions is that we often face a variety of data, each requiring a different type of layout: we don't represent the distribution of categorical variables similarly to continuous variables, and regarding the latter heavily skewed data may require a special treatment. The aim of `fplot` is to automatically make choices for the user in order to always display meaningful (and hopefully beautiful!) graphs. 9 | 10 | This brief description shows a gallery of `fplot` possibilities. For a more detailed introduction, please see the [walk-through](https://lrberge.github.io/fplot/articles/fplot_walkthrough.html). 11 | 12 | The data sets used are `us_pub_econ` (from `fplot`) relating to publications in economics from US institutions, `trade` (from package `fixest`) relating to trade value between countries for some products in the European Union, and the `iris` data set (from base `R`). 13 | 14 | One aim of `fplot`is to easily export graphs, it therefore includes a tool to relabel the variable names *globally* (once and for all). The following line is run before plotting the graphs: 15 | 16 | ``` 17 | setFplot_dict(c(Origin = "Exporting Country", Destination = "Importing Country", Euros = "Exports Value in €", 18 | jnl_top_25p = "Pub. in Top 25% journal", jnl_top_5p = "Publications in Top 5% journal", 19 | journal = "Journal", institution = "U.S. Institution", Petal.Length = "Petal Length")) 20 | ``` 21 | 22 | 23 | The code to run the plots are in the titles of the graphs. You'll notice that the same command line can result in a set of different graphs. 24 | 25 | ![](man/figures/regular_pub.png) 26 | 27 | ![](man/figures/regular_trade.png) 28 | 29 | ![](man/figures/regular_iris.png) 30 | 31 | ![](man/figures/conditional_pub_1.png) 32 | 33 | ![](man/figures/conditional_pub_2.png) 34 | 35 | ![](man/figures/conditional_pub_3_bis.png) 36 | 37 | ![](man/figures/conditional_trade_1.png) 38 | 39 | ![](man/figures/conditional_trade_2.png) 40 | 41 | ![](man/figures/conditional_iris_1.png) 42 | 43 | ![](man/figures/conditional_iris_2.png) 44 | 45 | ![](man/figures/conditional_iris_3.png) 46 | 47 | ![](man/figures/weighted_pub_1.png) 48 | 49 | ![](man/figures/weighted_pub_2.png) 50 | 51 | ![](man/figures/weighted_trade_1.png) 52 | 53 | ![](man/figures/weighted_trade_2.png) 54 | 55 | ![](man/figures/weighted_conditional_trade_1.png) 56 | 57 | ![](man/figures/weighted_conditional_trade_2.png) 58 | 59 | ![](man/figures/weighted_stacked_pub.png) 60 | 61 | ![](man/figures/weighted_stacked_trade.png) 62 | 63 | ![](man/figures/cumul_pub.png) 64 | 65 | ![](man/figures/cumul_trade.png) 66 | 67 | 68 | -------------------------------------------------------------------------------- /data/datalist: -------------------------------------------------------------------------------- 1 | us_pub_econ 2 | -------------------------------------------------------------------------------- /data/us_pub_econ.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/data/us_pub_econ.RData -------------------------------------------------------------------------------- /docs/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Page not found (404) • fplot 9 | 10 | 11 | 12 | 13 | 14 | 15 | 19 | 20 | 21 | 22 | 23 |
24 |
69 | 70 | 71 | 72 | 73 |
74 |
75 | 78 | 79 | Content not found. Please use links in the navbar. 80 | 81 |
82 | 83 | 87 | 88 |
89 | 90 | 91 | 92 |
96 | 97 |
98 |

99 |

Site built with pkgdown 2.0.7.

100 |
101 | 102 |
103 |
104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /docs/articles/export_example_10pt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/articles/export_example_10pt.png -------------------------------------------------------------------------------- /docs/articles/export_example_12pt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/articles/export_example_12pt.png -------------------------------------------------------------------------------- /docs/articles/fplot_walkthrough_files/figure-html/unnamed-chunk-10-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/articles/fplot_walkthrough_files/figure-html/unnamed-chunk-10-1.png -------------------------------------------------------------------------------- /docs/articles/fplot_walkthrough_files/figure-html/unnamed-chunk-14-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/articles/fplot_walkthrough_files/figure-html/unnamed-chunk-14-1.png -------------------------------------------------------------------------------- /docs/articles/fplot_walkthrough_files/figure-html/unnamed-chunk-16-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/articles/fplot_walkthrough_files/figure-html/unnamed-chunk-16-1.png -------------------------------------------------------------------------------- /docs/articles/fplot_walkthrough_files/figure-html/unnamed-chunk-17-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/articles/fplot_walkthrough_files/figure-html/unnamed-chunk-17-1.png -------------------------------------------------------------------------------- /docs/articles/fplot_walkthrough_files/figure-html/unnamed-chunk-18-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/articles/fplot_walkthrough_files/figure-html/unnamed-chunk-18-1.png -------------------------------------------------------------------------------- /docs/articles/fplot_walkthrough_files/figure-html/unnamed-chunk-19-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/articles/fplot_walkthrough_files/figure-html/unnamed-chunk-19-1.png -------------------------------------------------------------------------------- /docs/articles/fplot_walkthrough_files/figure-html/unnamed-chunk-20-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/articles/fplot_walkthrough_files/figure-html/unnamed-chunk-20-1.png -------------------------------------------------------------------------------- /docs/articles/fplot_walkthrough_files/figure-html/unnamed-chunk-21-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/articles/fplot_walkthrough_files/figure-html/unnamed-chunk-21-1.png -------------------------------------------------------------------------------- /docs/articles/fplot_walkthrough_files/figure-html/unnamed-chunk-22-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/articles/fplot_walkthrough_files/figure-html/unnamed-chunk-22-1.png -------------------------------------------------------------------------------- /docs/articles/fplot_walkthrough_files/figure-html/unnamed-chunk-23-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/articles/fplot_walkthrough_files/figure-html/unnamed-chunk-23-1.png -------------------------------------------------------------------------------- /docs/articles/fplot_walkthrough_files/figure-html/unnamed-chunk-24-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/articles/fplot_walkthrough_files/figure-html/unnamed-chunk-24-1.png -------------------------------------------------------------------------------- /docs/articles/fplot_walkthrough_files/figure-html/unnamed-chunk-25-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/articles/fplot_walkthrough_files/figure-html/unnamed-chunk-25-1.png -------------------------------------------------------------------------------- /docs/articles/fplot_walkthrough_files/figure-html/unnamed-chunk-26-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/articles/fplot_walkthrough_files/figure-html/unnamed-chunk-26-1.png -------------------------------------------------------------------------------- /docs/articles/fplot_walkthrough_files/figure-html/unnamed-chunk-27-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/articles/fplot_walkthrough_files/figure-html/unnamed-chunk-27-1.png -------------------------------------------------------------------------------- /docs/articles/fplot_walkthrough_files/figure-html/unnamed-chunk-28-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/articles/fplot_walkthrough_files/figure-html/unnamed-chunk-28-1.png -------------------------------------------------------------------------------- /docs/articles/fplot_walkthrough_files/figure-html/unnamed-chunk-29-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/articles/fplot_walkthrough_files/figure-html/unnamed-chunk-29-1.png -------------------------------------------------------------------------------- /docs/articles/fplot_walkthrough_files/figure-html/unnamed-chunk-5-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/articles/fplot_walkthrough_files/figure-html/unnamed-chunk-5-1.png -------------------------------------------------------------------------------- /docs/articles/fplot_walkthrough_files/figure-html/unnamed-chunk-6-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/articles/fplot_walkthrough_files/figure-html/unnamed-chunk-6-1.png -------------------------------------------------------------------------------- /docs/articles/fplot_walkthrough_files/figure-html/unnamed-chunk-7-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/articles/fplot_walkthrough_files/figure-html/unnamed-chunk-7-1.png -------------------------------------------------------------------------------- /docs/articles/fplot_walkthrough_files/figure-html/unnamed-chunk-8-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/articles/fplot_walkthrough_files/figure-html/unnamed-chunk-8-1.png -------------------------------------------------------------------------------- /docs/articles/fplot_walkthrough_files/figure-html/unnamed-chunk-9-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/articles/fplot_walkthrough_files/figure-html/unnamed-chunk-9-1.png -------------------------------------------------------------------------------- /docs/articles/images/export/example_10pt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/articles/images/export/example_10pt.png -------------------------------------------------------------------------------- /docs/articles/images/export/example_12pt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/articles/images/export/example_12pt.png -------------------------------------------------------------------------------- /docs/articles/images/export/example_12pt_sideways.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/articles/images/export/example_12pt_sideways.png -------------------------------------------------------------------------------- /docs/articles/images/export/example_12pt_tall.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/articles/images/export/example_12pt_tall.png -------------------------------------------------------------------------------- /docs/articles/images/export_example_10pt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/articles/images/export_example_10pt.png -------------------------------------------------------------------------------- /docs/articles/images/export_example_12pt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/articles/images/export_example_12pt.png -------------------------------------------------------------------------------- /docs/articles/images/export_example_12pt_sideways.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/articles/images/export_example_12pt_sideways.png -------------------------------------------------------------------------------- /docs/articles/images/export_example_12pt_tall.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/articles/images/export_example_12pt_tall.png -------------------------------------------------------------------------------- /docs/articles/index.html: -------------------------------------------------------------------------------- 1 | 2 | Articles • fplot 6 | 7 | 8 |
9 |
47 | 48 | 49 | 50 |
51 |
52 | 55 | 56 |
57 |

All vignettes

58 |

59 | 60 |
Exporting graphs
61 |
62 |
fplot walkthrough
63 |
64 |
65 |
66 |
67 | 68 | 69 |
72 | 73 |
74 |

Site built with pkgdown 2.0.7.

75 |
76 | 77 |
78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /docs/authors.html: -------------------------------------------------------------------------------- 1 | 2 | Authors and Citation • fplot 6 | 7 | 8 |
9 |
47 | 48 | 49 | 50 |
51 |
52 |
53 | 56 | 57 | 58 |
  • 59 |

    Laurent Berge. Author, maintainer. 60 |

    61 |
  • 62 |
63 |
64 |
65 |

Citation

66 | 67 |
68 |
69 | 70 | 71 |

Berge L (2023). 72 | fplot: Automatic Distribution Graphs Using Formulas. 73 | R package version 1.1.0. 74 |

75 |
@Manual{,
 76 |   title = {fplot: Automatic Distribution Graphs Using Formulas},
 77 |   author = {Laurent Berge},
 78 |   year = {2023},
 79 |   note = {R package version 1.1.0},
 80 | }
81 | 82 |
83 | 84 |
85 | 86 | 87 | 88 |
91 | 92 |
93 |

Site built with pkgdown 2.0.7.

94 |
95 | 96 |
97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /docs/bootstrap-toc.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | 6 | /* modified from https://github.com/twbs/bootstrap/blob/94b4076dd2efba9af71f0b18d4ee4b163aa9e0dd/docs/assets/css/src/docs.css#L548-L601 */ 7 | 8 | /* All levels of nav */ 9 | nav[data-toggle='toc'] .nav > li > a { 10 | display: block; 11 | padding: 4px 20px; 12 | font-size: 13px; 13 | font-weight: 500; 14 | color: #767676; 15 | } 16 | nav[data-toggle='toc'] .nav > li > a:hover, 17 | nav[data-toggle='toc'] .nav > li > a:focus { 18 | padding-left: 19px; 19 | color: #563d7c; 20 | text-decoration: none; 21 | background-color: transparent; 22 | border-left: 1px solid #563d7c; 23 | } 24 | nav[data-toggle='toc'] .nav > .active > a, 25 | nav[data-toggle='toc'] .nav > .active:hover > a, 26 | nav[data-toggle='toc'] .nav > .active:focus > a { 27 | padding-left: 18px; 28 | font-weight: bold; 29 | color: #563d7c; 30 | background-color: transparent; 31 | border-left: 2px solid #563d7c; 32 | } 33 | 34 | /* Nav: second level (shown on .active) */ 35 | nav[data-toggle='toc'] .nav .nav { 36 | display: none; /* Hide by default, but at >768px, show it */ 37 | padding-bottom: 10px; 38 | } 39 | nav[data-toggle='toc'] .nav .nav > li > a { 40 | padding-top: 1px; 41 | padding-bottom: 1px; 42 | padding-left: 30px; 43 | font-size: 12px; 44 | font-weight: normal; 45 | } 46 | nav[data-toggle='toc'] .nav .nav > li > a:hover, 47 | nav[data-toggle='toc'] .nav .nav > li > a:focus { 48 | padding-left: 29px; 49 | } 50 | nav[data-toggle='toc'] .nav .nav > .active > a, 51 | nav[data-toggle='toc'] .nav .nav > .active:hover > a, 52 | nav[data-toggle='toc'] .nav .nav > .active:focus > a { 53 | padding-left: 28px; 54 | font-weight: 500; 55 | } 56 | 57 | /* from https://github.com/twbs/bootstrap/blob/e38f066d8c203c3e032da0ff23cd2d6098ee2dd6/docs/assets/css/src/docs.css#L631-L634 */ 58 | nav[data-toggle='toc'] .nav > .active > ul { 59 | display: block; 60 | } 61 | -------------------------------------------------------------------------------- /docs/bootstrap-toc.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | (function() { 6 | 'use strict'; 7 | 8 | window.Toc = { 9 | helpers: { 10 | // return all matching elements in the set, or their descendants 11 | findOrFilter: function($el, selector) { 12 | // http://danielnouri.org/notes/2011/03/14/a-jquery-find-that-also-finds-the-root-element/ 13 | // http://stackoverflow.com/a/12731439/358804 14 | var $descendants = $el.find(selector); 15 | return $el.filter(selector).add($descendants).filter(':not([data-toc-skip])'); 16 | }, 17 | 18 | generateUniqueIdBase: function(el) { 19 | var text = $(el).text(); 20 | var anchor = text.trim().toLowerCase().replace(/[^A-Za-z0-9]+/g, '-'); 21 | return anchor || el.tagName.toLowerCase(); 22 | }, 23 | 24 | generateUniqueId: function(el) { 25 | var anchorBase = this.generateUniqueIdBase(el); 26 | for (var i = 0; ; i++) { 27 | var anchor = anchorBase; 28 | if (i > 0) { 29 | // add suffix 30 | anchor += '-' + i; 31 | } 32 | // check if ID already exists 33 | if (!document.getElementById(anchor)) { 34 | return anchor; 35 | } 36 | } 37 | }, 38 | 39 | generateAnchor: function(el) { 40 | if (el.id) { 41 | return el.id; 42 | } else { 43 | var anchor = this.generateUniqueId(el); 44 | el.id = anchor; 45 | return anchor; 46 | } 47 | }, 48 | 49 | createNavList: function() { 50 | return $(''); 51 | }, 52 | 53 | createChildNavList: function($parent) { 54 | var $childList = this.createNavList(); 55 | $parent.append($childList); 56 | return $childList; 57 | }, 58 | 59 | generateNavEl: function(anchor, text) { 60 | var $a = $(''); 61 | $a.attr('href', '#' + anchor); 62 | $a.text(text); 63 | var $li = $('
  • '); 64 | $li.append($a); 65 | return $li; 66 | }, 67 | 68 | generateNavItem: function(headingEl) { 69 | var anchor = this.generateAnchor(headingEl); 70 | var $heading = $(headingEl); 71 | var text = $heading.data('toc-text') || $heading.text(); 72 | return this.generateNavEl(anchor, text); 73 | }, 74 | 75 | // Find the first heading level (`

    `, then `

    `, etc.) that has more than one element. Defaults to 1 (for `

    `). 76 | getTopLevel: function($scope) { 77 | for (var i = 1; i <= 6; i++) { 78 | var $headings = this.findOrFilter($scope, 'h' + i); 79 | if ($headings.length > 1) { 80 | return i; 81 | } 82 | } 83 | 84 | return 1; 85 | }, 86 | 87 | // returns the elements for the top level, and the next below it 88 | getHeadings: function($scope, topLevel) { 89 | var topSelector = 'h' + topLevel; 90 | 91 | var secondaryLevel = topLevel + 1; 92 | var secondarySelector = 'h' + secondaryLevel; 93 | 94 | return this.findOrFilter($scope, topSelector + ',' + secondarySelector); 95 | }, 96 | 97 | getNavLevel: function(el) { 98 | return parseInt(el.tagName.charAt(1), 10); 99 | }, 100 | 101 | populateNav: function($topContext, topLevel, $headings) { 102 | var $context = $topContext; 103 | var $prevNav; 104 | 105 | var helpers = this; 106 | $headings.each(function(i, el) { 107 | var $newNav = helpers.generateNavItem(el); 108 | var navLevel = helpers.getNavLevel(el); 109 | 110 | // determine the proper $context 111 | if (navLevel === topLevel) { 112 | // use top level 113 | $context = $topContext; 114 | } else if ($prevNav && $context === $topContext) { 115 | // create a new level of the tree and switch to it 116 | $context = helpers.createChildNavList($prevNav); 117 | } // else use the current $context 118 | 119 | $context.append($newNav); 120 | 121 | $prevNav = $newNav; 122 | }); 123 | }, 124 | 125 | parseOps: function(arg) { 126 | var opts; 127 | if (arg.jquery) { 128 | opts = { 129 | $nav: arg 130 | }; 131 | } else { 132 | opts = arg; 133 | } 134 | opts.$scope = opts.$scope || $(document.body); 135 | return opts; 136 | } 137 | }, 138 | 139 | // accepts a jQuery object, or an options object 140 | init: function(opts) { 141 | opts = this.helpers.parseOps(opts); 142 | 143 | // ensure that the data attribute is in place for styling 144 | opts.$nav.attr('data-toggle', 'toc'); 145 | 146 | var $topContext = this.helpers.createChildNavList(opts.$nav); 147 | var topLevel = this.helpers.getTopLevel(opts.$scope); 148 | var $headings = this.helpers.getHeadings(opts.$scope, topLevel); 149 | this.helpers.populateNav($topContext, topLevel, $headings); 150 | } 151 | }; 152 | 153 | $(function() { 154 | $('nav[data-toggle="toc"]').each(function(i, el) { 155 | var $nav = $(el); 156 | Toc.init($nav); 157 | }); 158 | }); 159 | })(); 160 | -------------------------------------------------------------------------------- /docs/docsearch.js: -------------------------------------------------------------------------------- 1 | $(function() { 2 | 3 | // register a handler to move the focus to the search bar 4 | // upon pressing shift + "/" (i.e. "?") 5 | $(document).on('keydown', function(e) { 6 | if (e.shiftKey && e.keyCode == 191) { 7 | e.preventDefault(); 8 | $("#search-input").focus(); 9 | } 10 | }); 11 | 12 | $(document).ready(function() { 13 | // do keyword highlighting 14 | /* modified from https://jsfiddle.net/julmot/bL6bb5oo/ */ 15 | var mark = function() { 16 | 17 | var referrer = document.URL ; 18 | var paramKey = "q" ; 19 | 20 | if (referrer.indexOf("?") !== -1) { 21 | var qs = referrer.substr(referrer.indexOf('?') + 1); 22 | var qs_noanchor = qs.split('#')[0]; 23 | var qsa = qs_noanchor.split('&'); 24 | var keyword = ""; 25 | 26 | for (var i = 0; i < qsa.length; i++) { 27 | var currentParam = qsa[i].split('='); 28 | 29 | if (currentParam.length !== 2) { 30 | continue; 31 | } 32 | 33 | if (currentParam[0] == paramKey) { 34 | keyword = decodeURIComponent(currentParam[1].replace(/\+/g, "%20")); 35 | } 36 | } 37 | 38 | if (keyword !== "") { 39 | $(".contents").unmark({ 40 | done: function() { 41 | $(".contents").mark(keyword); 42 | } 43 | }); 44 | } 45 | } 46 | }; 47 | 48 | mark(); 49 | }); 50 | }); 51 | 52 | /* Search term highlighting ------------------------------*/ 53 | 54 | function matchedWords(hit) { 55 | var words = []; 56 | 57 | var hierarchy = hit._highlightResult.hierarchy; 58 | // loop to fetch from lvl0, lvl1, etc. 59 | for (var idx in hierarchy) { 60 | words = words.concat(hierarchy[idx].matchedWords); 61 | } 62 | 63 | var content = hit._highlightResult.content; 64 | if (content) { 65 | words = words.concat(content.matchedWords); 66 | } 67 | 68 | // return unique words 69 | var words_uniq = [...new Set(words)]; 70 | return words_uniq; 71 | } 72 | 73 | function updateHitURL(hit) { 74 | 75 | var words = matchedWords(hit); 76 | var url = ""; 77 | 78 | if (hit.anchor) { 79 | url = hit.url_without_anchor + '?q=' + escape(words.join(" ")) + '#' + hit.anchor; 80 | } else { 81 | url = hit.url + '?q=' + escape(words.join(" ")); 82 | } 83 | 84 | return url; 85 | } 86 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Automatic Distribution Graphs Using Formulas • fplot 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 20 | 21 | 22 | 23 | 24 |
    25 |
    70 | 71 | 72 | 73 | 74 |
    75 |
    76 |
    77 | 79 |

    Version Downloads

    80 |

    fplot is an R package made for the easy plotting of distributions.

    81 |

    The problem when it comes to distributions is that we often face a variety of data, each requiring a different type of layout: we don’t represent the distribution of categorical variables similarly to continuous variables, and regarding the latter heavily skewed data may require a special treatment. The aim of fplot is to automatically make choices for the user in order to always display meaningful (and hopefully beautiful!) graphs.

    82 |

    This brief description shows a gallery of fplot possibilities. For a more detailed introduction, please see the walk-through.

    83 |

    The data sets used are us_pub_econ (from fplot) relating to publications in economics from US institutions, trade (from package fixest) relating to trade value between countries for some products in the European Union, and the iris data set (from base R).

    84 |

    One aim of fplotis to easily export graphs, it therefore includes a tool to relabel the variable names globally (once and for all). The following line is run before plotting the graphs:

    85 |
    setFplot_dict(c(Origin = "Exporting Country", Destination = "Importing Country", Euros = "Exports Value in €", 
     86 |                 jnl_top_25p = "Pub. in Top 25% journal", jnl_top_5p = "Publications in Top 5% journal", 
     87 |                 journal = "Journal", institution = "U.S. Institution", Petal.Length = "Petal Length"))
    88 |

    The code to run the plots are in the titles of the graphs. You’ll notice that the same command line can result in a set of different graphs.

    89 |

    90 |

    91 |

    92 |

    93 |

    94 |

    95 |

    96 |

    97 |

    98 |

    99 |

    100 |

    101 |

    102 |

    103 |

    104 |

    105 |

    106 |

    107 |

    108 |

    109 |

    110 |
    111 |
    112 | 113 | 146 |
    147 | 148 | 149 |
    153 | 154 |
    155 |

    156 |

    Site built with pkgdown 2.0.7.

    157 |
    158 | 159 |
    160 |
    161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | -------------------------------------------------------------------------------- /docs/link.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /docs/pkgdown.css: -------------------------------------------------------------------------------- 1 | /* Sticky footer */ 2 | 3 | /** 4 | * Basic idea: https://philipwalton.github.io/solved-by-flexbox/demos/sticky-footer/ 5 | * Details: https://github.com/philipwalton/solved-by-flexbox/blob/master/assets/css/components/site.css 6 | * 7 | * .Site -> body > .container 8 | * .Site-content -> body > .container .row 9 | * .footer -> footer 10 | * 11 | * Key idea seems to be to ensure that .container and __all its parents__ 12 | * have height set to 100% 13 | * 14 | */ 15 | 16 | html, body { 17 | height: 100%; 18 | } 19 | 20 | body { 21 | position: relative; 22 | } 23 | 24 | body > .container { 25 | display: flex; 26 | height: 100%; 27 | flex-direction: column; 28 | } 29 | 30 | body > .container .row { 31 | flex: 1 0 auto; 32 | } 33 | 34 | footer { 35 | margin-top: 45px; 36 | padding: 35px 0 36px; 37 | border-top: 1px solid #e5e5e5; 38 | color: #666; 39 | display: flex; 40 | flex-shrink: 0; 41 | } 42 | footer p { 43 | margin-bottom: 0; 44 | } 45 | footer div { 46 | flex: 1; 47 | } 48 | footer .pkgdown { 49 | text-align: right; 50 | } 51 | footer p { 52 | margin-bottom: 0; 53 | } 54 | 55 | img.icon { 56 | float: right; 57 | } 58 | 59 | /* Ensure in-page images don't run outside their container */ 60 | .contents img { 61 | max-width: 100%; 62 | height: auto; 63 | } 64 | 65 | /* Fix bug in bootstrap (only seen in firefox) */ 66 | summary { 67 | display: list-item; 68 | } 69 | 70 | /* Typographic tweaking ---------------------------------*/ 71 | 72 | .contents .page-header { 73 | margin-top: calc(-60px + 1em); 74 | } 75 | 76 | dd { 77 | margin-left: 3em; 78 | } 79 | 80 | /* Section anchors ---------------------------------*/ 81 | 82 | a.anchor { 83 | display: none; 84 | margin-left: 5px; 85 | width: 20px; 86 | height: 20px; 87 | 88 | background-image: url(./link.svg); 89 | background-repeat: no-repeat; 90 | background-size: 20px 20px; 91 | background-position: center center; 92 | } 93 | 94 | h1:hover .anchor, 95 | h2:hover .anchor, 96 | h3:hover .anchor, 97 | h4:hover .anchor, 98 | h5:hover .anchor, 99 | h6:hover .anchor { 100 | display: inline-block; 101 | } 102 | 103 | /* Fixes for fixed navbar --------------------------*/ 104 | 105 | .contents h1, .contents h2, .contents h3, .contents h4 { 106 | padding-top: 60px; 107 | margin-top: -40px; 108 | } 109 | 110 | /* Navbar submenu --------------------------*/ 111 | 112 | .dropdown-submenu { 113 | position: relative; 114 | } 115 | 116 | .dropdown-submenu>.dropdown-menu { 117 | top: 0; 118 | left: 100%; 119 | margin-top: -6px; 120 | margin-left: -1px; 121 | border-radius: 0 6px 6px 6px; 122 | } 123 | 124 | .dropdown-submenu:hover>.dropdown-menu { 125 | display: block; 126 | } 127 | 128 | .dropdown-submenu>a:after { 129 | display: block; 130 | content: " "; 131 | float: right; 132 | width: 0; 133 | height: 0; 134 | border-color: transparent; 135 | border-style: solid; 136 | border-width: 5px 0 5px 5px; 137 | border-left-color: #cccccc; 138 | margin-top: 5px; 139 | margin-right: -10px; 140 | } 141 | 142 | .dropdown-submenu:hover>a:after { 143 | border-left-color: #ffffff; 144 | } 145 | 146 | .dropdown-submenu.pull-left { 147 | float: none; 148 | } 149 | 150 | .dropdown-submenu.pull-left>.dropdown-menu { 151 | left: -100%; 152 | margin-left: 10px; 153 | border-radius: 6px 0 6px 6px; 154 | } 155 | 156 | /* Sidebar --------------------------*/ 157 | 158 | #pkgdown-sidebar { 159 | margin-top: 30px; 160 | position: -webkit-sticky; 161 | position: sticky; 162 | top: 70px; 163 | } 164 | 165 | #pkgdown-sidebar h2 { 166 | font-size: 1.5em; 167 | margin-top: 1em; 168 | } 169 | 170 | #pkgdown-sidebar h2:first-child { 171 | margin-top: 0; 172 | } 173 | 174 | #pkgdown-sidebar .list-unstyled li { 175 | margin-bottom: 0.5em; 176 | } 177 | 178 | /* bootstrap-toc tweaks ------------------------------------------------------*/ 179 | 180 | /* All levels of nav */ 181 | 182 | nav[data-toggle='toc'] .nav > li > a { 183 | padding: 4px 20px 4px 6px; 184 | font-size: 1.5rem; 185 | font-weight: 400; 186 | color: inherit; 187 | } 188 | 189 | nav[data-toggle='toc'] .nav > li > a:hover, 190 | nav[data-toggle='toc'] .nav > li > a:focus { 191 | padding-left: 5px; 192 | color: inherit; 193 | border-left: 1px solid #878787; 194 | } 195 | 196 | nav[data-toggle='toc'] .nav > .active > a, 197 | nav[data-toggle='toc'] .nav > .active:hover > a, 198 | nav[data-toggle='toc'] .nav > .active:focus > a { 199 | padding-left: 5px; 200 | font-size: 1.5rem; 201 | font-weight: 400; 202 | color: inherit; 203 | border-left: 2px solid #878787; 204 | } 205 | 206 | /* Nav: second level (shown on .active) */ 207 | 208 | nav[data-toggle='toc'] .nav .nav { 209 | display: none; /* Hide by default, but at >768px, show it */ 210 | padding-bottom: 10px; 211 | } 212 | 213 | nav[data-toggle='toc'] .nav .nav > li > a { 214 | padding-left: 16px; 215 | font-size: 1.35rem; 216 | } 217 | 218 | nav[data-toggle='toc'] .nav .nav > li > a:hover, 219 | nav[data-toggle='toc'] .nav .nav > li > a:focus { 220 | padding-left: 15px; 221 | } 222 | 223 | nav[data-toggle='toc'] .nav .nav > .active > a, 224 | nav[data-toggle='toc'] .nav .nav > .active:hover > a, 225 | nav[data-toggle='toc'] .nav .nav > .active:focus > a { 226 | padding-left: 15px; 227 | font-weight: 500; 228 | font-size: 1.35rem; 229 | } 230 | 231 | /* orcid ------------------------------------------------------------------- */ 232 | 233 | .orcid { 234 | font-size: 16px; 235 | color: #A6CE39; 236 | /* margins are required by official ORCID trademark and display guidelines */ 237 | margin-left:4px; 238 | margin-right:4px; 239 | vertical-align: middle; 240 | } 241 | 242 | /* Reference index & topics ----------------------------------------------- */ 243 | 244 | .ref-index th {font-weight: normal;} 245 | 246 | .ref-index td {vertical-align: top; min-width: 100px} 247 | .ref-index .icon {width: 40px;} 248 | .ref-index .alias {width: 40%;} 249 | .ref-index-icons .alias {width: calc(40% - 40px);} 250 | .ref-index .title {width: 60%;} 251 | 252 | .ref-arguments th {text-align: right; padding-right: 10px;} 253 | .ref-arguments th, .ref-arguments td {vertical-align: top; min-width: 100px} 254 | .ref-arguments .name {width: 20%;} 255 | .ref-arguments .desc {width: 80%;} 256 | 257 | /* Nice scrolling for wide elements --------------------------------------- */ 258 | 259 | table { 260 | display: block; 261 | overflow: auto; 262 | } 263 | 264 | /* Syntax highlighting ---------------------------------------------------- */ 265 | 266 | pre, code, pre code { 267 | background-color: #f8f8f8; 268 | color: #333; 269 | } 270 | pre, pre code { 271 | white-space: pre-wrap; 272 | word-break: break-all; 273 | overflow-wrap: break-word; 274 | } 275 | 276 | pre { 277 | border: 1px solid #eee; 278 | } 279 | 280 | pre .img, pre .r-plt { 281 | margin: 5px 0; 282 | } 283 | 284 | pre .img img, pre .r-plt img { 285 | background-color: #fff; 286 | } 287 | 288 | code a, pre a { 289 | color: #375f84; 290 | } 291 | 292 | a.sourceLine:hover { 293 | text-decoration: none; 294 | } 295 | 296 | .fl {color: #1514b5;} 297 | .fu {color: #000000;} /* function */ 298 | .ch,.st {color: #036a07;} /* string */ 299 | .kw {color: #264D66;} /* keyword */ 300 | .co {color: #888888;} /* comment */ 301 | 302 | .error {font-weight: bolder;} 303 | .warning {font-weight: bolder;} 304 | 305 | /* Clipboard --------------------------*/ 306 | 307 | .hasCopyButton { 308 | position: relative; 309 | } 310 | 311 | .btn-copy-ex { 312 | position: absolute; 313 | right: 0; 314 | top: 0; 315 | visibility: hidden; 316 | } 317 | 318 | .hasCopyButton:hover button.btn-copy-ex { 319 | visibility: visible; 320 | } 321 | 322 | /* headroom.js ------------------------ */ 323 | 324 | .headroom { 325 | will-change: transform; 326 | transition: transform 200ms linear; 327 | } 328 | .headroom--pinned { 329 | transform: translateY(0%); 330 | } 331 | .headroom--unpinned { 332 | transform: translateY(-100%); 333 | } 334 | 335 | /* mark.js ----------------------------*/ 336 | 337 | mark { 338 | background-color: rgba(255, 255, 51, 0.5); 339 | border-bottom: 2px solid rgba(255, 153, 51, 0.3); 340 | padding: 1px; 341 | } 342 | 343 | /* vertical spacing after htmlwidgets */ 344 | .html-widget { 345 | margin-bottom: 10px; 346 | } 347 | 348 | /* fontawesome ------------------------ */ 349 | 350 | .fab { 351 | font-family: "Font Awesome 5 Brands" !important; 352 | } 353 | 354 | /* don't display links in code chunks when printing */ 355 | /* source: https://stackoverflow.com/a/10781533 */ 356 | @media print { 357 | code a:link:after, code a:visited:after { 358 | content: ""; 359 | } 360 | } 361 | 362 | /* Section anchors --------------------------------- 363 | Added in pandoc 2.11: https://github.com/jgm/pandoc-templates/commit/9904bf71 364 | */ 365 | 366 | div.csl-bib-body { } 367 | div.csl-entry { 368 | clear: both; 369 | } 370 | .hanging-indent div.csl-entry { 371 | margin-left:2em; 372 | text-indent:-2em; 373 | } 374 | div.csl-left-margin { 375 | min-width:2em; 376 | float:left; 377 | } 378 | div.csl-right-inline { 379 | margin-left:2em; 380 | padding-left:1em; 381 | } 382 | div.csl-indent { 383 | margin-left: 2em; 384 | } 385 | -------------------------------------------------------------------------------- /docs/pkgdown.js: -------------------------------------------------------------------------------- 1 | /* http://gregfranko.com/blog/jquery-best-practices/ */ 2 | (function($) { 3 | $(function() { 4 | 5 | $('.navbar-fixed-top').headroom(); 6 | 7 | $('body').css('padding-top', $('.navbar').height() + 10); 8 | $(window).resize(function(){ 9 | $('body').css('padding-top', $('.navbar').height() + 10); 10 | }); 11 | 12 | $('[data-toggle="tooltip"]').tooltip(); 13 | 14 | var cur_path = paths(location.pathname); 15 | var links = $("#navbar ul li a"); 16 | var max_length = -1; 17 | var pos = -1; 18 | for (var i = 0; i < links.length; i++) { 19 | if (links[i].getAttribute("href") === "#") 20 | continue; 21 | // Ignore external links 22 | if (links[i].host !== location.host) 23 | continue; 24 | 25 | var nav_path = paths(links[i].pathname); 26 | 27 | var length = prefix_length(nav_path, cur_path); 28 | if (length > max_length) { 29 | max_length = length; 30 | pos = i; 31 | } 32 | } 33 | 34 | // Add class to parent
  • , and enclosing
  • if in dropdown 35 | if (pos >= 0) { 36 | var menu_anchor = $(links[pos]); 37 | menu_anchor.parent().addClass("active"); 38 | menu_anchor.closest("li.dropdown").addClass("active"); 39 | } 40 | }); 41 | 42 | function paths(pathname) { 43 | var pieces = pathname.split("/"); 44 | pieces.shift(); // always starts with / 45 | 46 | var end = pieces[pieces.length - 1]; 47 | if (end === "index.html" || end === "") 48 | pieces.pop(); 49 | return(pieces); 50 | } 51 | 52 | // Returns -1 if not found 53 | function prefix_length(needle, haystack) { 54 | if (needle.length > haystack.length) 55 | return(-1); 56 | 57 | // Special case for length-0 haystack, since for loop won't run 58 | if (haystack.length === 0) { 59 | return(needle.length === 0 ? 0 : -1); 60 | } 61 | 62 | for (var i = 0; i < haystack.length; i++) { 63 | if (needle[i] != haystack[i]) 64 | return(i); 65 | } 66 | 67 | return(haystack.length); 68 | } 69 | 70 | /* Clipboard --------------------------*/ 71 | 72 | function changeTooltipMessage(element, msg) { 73 | var tooltipOriginalTitle=element.getAttribute('data-original-title'); 74 | element.setAttribute('data-original-title', msg); 75 | $(element).tooltip('show'); 76 | element.setAttribute('data-original-title', tooltipOriginalTitle); 77 | } 78 | 79 | if(ClipboardJS.isSupported()) { 80 | $(document).ready(function() { 81 | var copyButton = ""; 82 | 83 | $("div.sourceCode").addClass("hasCopyButton"); 84 | 85 | // Insert copy buttons: 86 | $(copyButton).prependTo(".hasCopyButton"); 87 | 88 | // Initialize tooltips: 89 | $('.btn-copy-ex').tooltip({container: 'body'}); 90 | 91 | // Initialize clipboard: 92 | var clipboardBtnCopies = new ClipboardJS('[data-clipboard-copy]', { 93 | text: function(trigger) { 94 | return trigger.parentNode.textContent.replace(/\n#>[^\n]*/g, ""); 95 | } 96 | }); 97 | 98 | clipboardBtnCopies.on('success', function(e) { 99 | changeTooltipMessage(e.trigger, 'Copied!'); 100 | e.clearSelection(); 101 | }); 102 | 103 | clipboardBtnCopies.on('error', function() { 104 | changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy'); 105 | }); 106 | }); 107 | } 108 | })(window.jQuery || window.$) 109 | -------------------------------------------------------------------------------- /docs/pkgdown.yml: -------------------------------------------------------------------------------- 1 | pandoc: '3.1' 2 | pkgdown: 2.0.7 3 | pkgdown_sha: ~ 4 | articles: 5 | Exporting_graphs: Exporting_graphs.html 6 | fplot_walkthrough: fplot_walkthrough.html 7 | last_built: 2023-08-24T14:44Z 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/Rplot001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/Rplot001.png -------------------------------------------------------------------------------- /docs/reference/Rplot002.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/Rplot002.png -------------------------------------------------------------------------------- /docs/reference/Rplot003.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/Rplot003.png -------------------------------------------------------------------------------- /docs/reference/Rplot004.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/Rplot004.png -------------------------------------------------------------------------------- /docs/reference/Rplot005.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/Rplot005.png -------------------------------------------------------------------------------- /docs/reference/Rplot006.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/Rplot006.png -------------------------------------------------------------------------------- /docs/reference/Rplot007.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/Rplot007.png -------------------------------------------------------------------------------- /docs/reference/Rplot008.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/Rplot008.png -------------------------------------------------------------------------------- /docs/reference/Rplot009.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/Rplot009.png -------------------------------------------------------------------------------- /docs/reference/Rplot010.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/Rplot010.png -------------------------------------------------------------------------------- /docs/reference/Rplot011.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/Rplot011.png -------------------------------------------------------------------------------- /docs/reference/export_graph_start-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/export_graph_start-1.png -------------------------------------------------------------------------------- /docs/reference/figures/conditional_iris_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/figures/conditional_iris_1.png -------------------------------------------------------------------------------- /docs/reference/figures/conditional_iris_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/figures/conditional_iris_2.png -------------------------------------------------------------------------------- /docs/reference/figures/conditional_iris_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/figures/conditional_iris_3.png -------------------------------------------------------------------------------- /docs/reference/figures/conditional_pub_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/figures/conditional_pub_1.png -------------------------------------------------------------------------------- /docs/reference/figures/conditional_pub_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/figures/conditional_pub_2.png -------------------------------------------------------------------------------- /docs/reference/figures/conditional_pub_3_bis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/figures/conditional_pub_3_bis.png -------------------------------------------------------------------------------- /docs/reference/figures/conditional_trade_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/figures/conditional_trade_1.png -------------------------------------------------------------------------------- /docs/reference/figures/conditional_trade_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/figures/conditional_trade_2.png -------------------------------------------------------------------------------- /docs/reference/figures/cumul_iris.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/figures/cumul_iris.png -------------------------------------------------------------------------------- /docs/reference/figures/cumul_pub.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/figures/cumul_pub.png -------------------------------------------------------------------------------- /docs/reference/figures/cumul_trade.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/figures/cumul_trade.png -------------------------------------------------------------------------------- /docs/reference/figures/export/example_10pt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/figures/export/example_10pt.png -------------------------------------------------------------------------------- /docs/reference/figures/export/example_12pt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/figures/export/example_12pt.png -------------------------------------------------------------------------------- /docs/reference/figures/export/example_12pt_sideways.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/figures/export/example_12pt_sideways.png -------------------------------------------------------------------------------- /docs/reference/figures/export/example_12pt_tall.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/figures/export/example_12pt_tall.png -------------------------------------------------------------------------------- /docs/reference/figures/regular_iris.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/figures/regular_iris.png -------------------------------------------------------------------------------- /docs/reference/figures/regular_pub.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/figures/regular_pub.png -------------------------------------------------------------------------------- /docs/reference/figures/regular_trade.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/figures/regular_trade.png -------------------------------------------------------------------------------- /docs/reference/figures/weighted_conditional_trade_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/figures/weighted_conditional_trade_1.png -------------------------------------------------------------------------------- /docs/reference/figures/weighted_conditional_trade_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/figures/weighted_conditional_trade_2.png -------------------------------------------------------------------------------- /docs/reference/figures/weighted_pub_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/figures/weighted_pub_1.png -------------------------------------------------------------------------------- /docs/reference/figures/weighted_pub_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/figures/weighted_pub_2.png -------------------------------------------------------------------------------- /docs/reference/figures/weighted_stacked_pub.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/figures/weighted_stacked_pub.png -------------------------------------------------------------------------------- /docs/reference/figures/weighted_stacked_trade.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/figures/weighted_stacked_trade.png -------------------------------------------------------------------------------- /docs/reference/figures/weighted_trade_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/figures/weighted_trade_1.png -------------------------------------------------------------------------------- /docs/reference/figures/weighted_trade_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/figures/weighted_trade_2.png -------------------------------------------------------------------------------- /docs/reference/fit.off.html: -------------------------------------------------------------------------------- 1 | 2 | Closes the current plotting device and shows the result in the viewer — fit.off • fplot 7 | 8 | 9 |
    10 |
    48 | 49 | 50 | 51 |
    52 |
    53 | 58 | 59 |
    60 |

    This function is deprecated: Please use the functions export_graph_start() 61 | and export_graph_end() instead.

    62 |
    63 | 64 |
    65 |
    fit.off()
    66 |
    67 | 68 |
    69 |

    Value

    70 | 71 | 72 |

    This function does not return anything in R. It closes the connection between the 73 | R graphics engine and a file that has been defined via one of the functions: 74 | pdf_fitpng_fit

    75 |
    76 |
    77 |

    Details

    78 |

    To be used in combination with pdf_fit or png_fit 79 | when exporting images. It performs exactly the same thing as dev.off() but additionaly 80 | shows the resulting graph in the viewer pane provided you're using RStudio.

    81 |

    To view the results of PDF exports, the function pdf_convert from package pdftools 82 | is used to convert the PDF files into images -- so you need to have installed 83 | pdftools to make it work.

    84 |

    In PDFs, only the first page will be viewed.

    85 |
    86 |
    87 |

    See also

    88 |

    The tool to set the page size and the exporting defaults: setFplot_page. 89 | Exporting functions pdf_fit, png_fit, 90 | jpeg_fit.

    91 |

    The functions export_graph_start() and export_graph_end() provide similar features.

    92 |
    93 |
    94 |

    Author

    95 |

    Laurent Berge

    96 |
    97 | 98 |
    99 |

    Examples

    100 |
    
    101 | # Exportation example
    102 | # The functions pdf_fit, png_fit, etc, guarantee the right
    103 | #  point size of the texts present in the graph.
    104 | # But you must give the exact size the graph will take in your final document.
    105 | # => first use the function setFplot_page, default is:
    106 | # setFplot_page(page = "us", margins = "normal")
    107 | # By default the graph takes 100% of the text width
    108 | 
    109 | data(us_pub_econ)
    110 | 
    111 | tmpFile = file.path(tempdir(), "DISTR -- institutions.png")
    112 | 
    113 | png_fit(tmpFile)
    114 | plot_distr(~institution, us_pub_econ)
    115 | fit.off()
    116 | 
    117 | # What's the consequence of increasing the point size of the text?
    118 | png_fit(tmpFile, pt = 15)
    119 | plot_distr(~institution, us_pub_econ)
    120 | fit.off()
    121 | 
    122 | 
    123 | 
    124 |
    125 |
    126 | 129 |
    130 | 131 | 132 |
    135 | 136 |
    137 |

    Site built with pkgdown 2.0.7.

    138 |
    139 | 140 |
    141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | -------------------------------------------------------------------------------- /docs/reference/fplot-package.html: -------------------------------------------------------------------------------- 1 | 2 | Aggregate/conditional graphs and automatic layout using formulas — fplot-package • fplot 6 | 7 | 8 |
    9 |
    47 | 48 | 49 | 50 |
    51 |
    52 | 57 | 58 |
    59 |

    fplot provides automatic plotting of common graphs (distributions, lines, bar plots and boxplots). The syntax uses formulas, allowing aggregate/conditional/weighted graphs with minimum efforts. The many arguments are automatically adjusted to the data in order to provide the nicest and most meaningful graphs.

    60 |
    61 | 62 | 63 |
    64 |

    Details

    65 |

    The core functions is plot_distr to draw distributions. 66 | Two other graphical functions are provided for convenience: plot_lines to represent the (usually temporal) evolution of some variables, and plot_box to easily represent conditional boxplots.

    67 |

    It also integrates tools to easily export graphs: pdf_fit and png_fit. In these functions, instead of providing the size of the graphics, you instead give the point size that the text should have in the final document--because an exported graph usually ends up in a document. You can set the size of your document with the function setFplot_page. If you use the function fit.off to close the connection, you will also see how the export looks like in the Viewer pane.

    68 |
    69 |
    70 |

    Author

    71 |

    Maintainer: Laurent Berge laurent.berge@u-bordeaux.fr

    72 |
    73 | 74 |
    75 | 78 |
    79 | 80 | 81 |
    84 | 85 |
    86 |

    Site built with pkgdown 2.0.7.

    87 |
    88 | 89 |
    90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /docs/reference/index.html: -------------------------------------------------------------------------------- 1 | 2 | Function reference • fplot 6 | 7 | 8 |
    9 |
    47 | 48 | 49 | 50 |
    51 |
    52 | 55 | 56 | 60 | 63 | 64 | 67 | 68 | 71 | 72 | 75 | 76 | 79 | 80 | 83 | 84 | 87 | 88 | 91 | 92 | 95 | 96 | 99 | 100 | 103 | 104 | 107 | 108 |
    57 |

    All functions

    58 |

    59 |
    61 |

    export_graph_start() export_graph_end()

    62 |

    Graph export with garanteed text size

    65 |

    fit.off()

    66 |

    Closes the current plotting device and shows the result in the viewer

    69 |

    fplot fplot-package

    70 |

    Aggregate/conditional graphs and automatic layout using formulas

    73 |

    pdf_fit()

    74 |

    PDF export with guaranteed text size

    77 |

    plot_box()

    78 |

    Boxplots with possibly moderators

    81 |

    plot_distr()

    82 |

    Plot distributions, possibly conditional

    85 |

    plot_lines()

    86 |

    Display means conditionnally on some other values

    89 |

    png_fit() tiff_fit() jpeg_fit() bmp_fit()

    90 |

    PNG export with guaranteed text size

    93 |

    setFplot_dict() getFplot_dict

    94 |

    Sets/gets the dictionary used in fplot

    97 |

    setFplot_distr() getFplot_distr()

    98 |

    Sets the defaults of plot_distr

    101 |

    setFplot_page() getFplot_page()

    102 |

    Sets the target page size for figure exporting

    105 |

    us_pub_econ

    106 |

    Publication data sample

    109 | 110 | 113 |
    114 | 115 | 116 |
    119 | 120 |
    121 |

    Site built with pkgdown 2.0.7.

    122 |
    123 | 124 |
    125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | -------------------------------------------------------------------------------- /docs/reference/plot_box-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/plot_box-1.png -------------------------------------------------------------------------------- /docs/reference/plot_box-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/plot_box-2.png -------------------------------------------------------------------------------- /docs/reference/plot_box-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/plot_box-3.png -------------------------------------------------------------------------------- /docs/reference/plot_box-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/plot_box-4.png -------------------------------------------------------------------------------- /docs/reference/plot_box-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/plot_box-5.png -------------------------------------------------------------------------------- /docs/reference/plot_distr-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/plot_distr-1.png -------------------------------------------------------------------------------- /docs/reference/plot_distr-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/plot_distr-2.png -------------------------------------------------------------------------------- /docs/reference/plot_distr-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/plot_distr-3.png -------------------------------------------------------------------------------- /docs/reference/plot_distr-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/plot_distr-4.png -------------------------------------------------------------------------------- /docs/reference/plot_distr-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/plot_distr-5.png -------------------------------------------------------------------------------- /docs/reference/plot_distr-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/plot_distr-6.png -------------------------------------------------------------------------------- /docs/reference/plot_distr-7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/plot_distr-7.png -------------------------------------------------------------------------------- /docs/reference/plot_distr-8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/plot_distr-8.png -------------------------------------------------------------------------------- /docs/reference/plot_distr-9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/plot_distr-9.png -------------------------------------------------------------------------------- /docs/reference/plot_lines-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/plot_lines-1.png -------------------------------------------------------------------------------- /docs/reference/plot_lines-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/plot_lines-2.png -------------------------------------------------------------------------------- /docs/reference/plot_lines-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/plot_lines-3.png -------------------------------------------------------------------------------- /docs/reference/setFplot_dict-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/setFplot_dict-1.png -------------------------------------------------------------------------------- /docs/reference/setFplot_dict.html: -------------------------------------------------------------------------------- 1 | 2 | Sets/gets the dictionary used in fplot — setFplot_dict • fplot 11 | 12 | 13 |
    14 |
    52 | 53 | 54 | 55 |
    56 |
    57 | 62 | 63 |
    64 |

    Sets/gets the default dictionary used to rename the axes/moderator variables 65 | in the functions of the package fplot. The dictionaries are used to relabel 66 | variables (usually towards a fancier, more explicit formatting) that can be useful 67 | not to explicitly use the arguments xlab/ylab when exporting graphs. By setting 68 | the dictionary with setFplot_dict, you can avoid providing the argument 69 | dict in fplot functions.

    70 |
    71 | 72 |
    73 |
    setFplot_dict(dict)
     74 | 
     75 | getFplot_dict
    76 |
    77 | 78 |
    79 |

    Format

    80 |

    An object of class function of length 1.

    81 |
    82 |
    83 |

    Arguments

    84 |
    dict
    85 |

    A named character vector. E.g. to change my variable named "us_md" 86 | and "state" to (resp.) "$ miilion" and "U.S. state", then use 87 | dict = c(us_md="$ million", state = "U.S. state").

    88 | 89 |
    90 |
    91 |

    Value

    92 | 93 | 94 |

    The function setFplot_dict() does not return anything, it only sets an option after checking 95 | the format of the arguments.

    96 | 97 | 98 |

    The function getFplot_dict() returns a named vector representing the 99 | dictionary set in setFplot_dict().

    100 |
    101 |
    102 |

    Details

    103 |

    This function stores a named vector in the option "fplot_dict". 104 | The dictionary is automatically accessed by all fplot functions.

    105 |
    106 |
    107 |

    Author

    108 |

    Laurent Berge

    109 |
    110 | 111 |
    112 |

    Examples

    113 |
    
    114 | data(airquality)
    115 | setFplot_dict(c(Ozone = "Ozone (ppb)"))
    116 | plot_distr(Ozone ~ Month, airquality, weight.fun = mean)
    117 | #> NOTE: 37 observations with NAs (weight: 37)
    118 | 
    119 | 
    120 | 
    121 |
    122 |
    123 | 126 |
    127 | 128 | 129 |
    132 | 133 |
    134 |

    Site built with pkgdown 2.0.7.

    135 |
    136 | 137 |
    138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | -------------------------------------------------------------------------------- /docs/reference/setFplot_distr-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/setFplot_distr-1.png -------------------------------------------------------------------------------- /docs/reference/setFplot_distr-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/docs/reference/setFplot_distr-2.png -------------------------------------------------------------------------------- /docs/reference/us_pub_econ.html: -------------------------------------------------------------------------------- 1 | 2 | Publication data sample — us_pub_econ • fplot 6 | 7 | 8 |
    9 |
    47 | 48 | 49 | 50 |
    51 |
    52 | 57 | 58 |
    59 |

    This data reports the publications of U.S. institutions in the field of economics between 1985 and 1990.

    60 |
    61 | 62 |
    63 |
    data(us_pub_econ)
    64 |
    65 | 66 |
    67 |

    Format

    68 |

    us_pub_econ is a data table with 30,756 observations and 6 variables.

    69 |
    • paper_id: Numeric identifier of the publication.

    • 70 |
    • year: Year of publication.

    • 71 |
    • institution: Institution of the authors of the publication.

    • 72 |
    • journal: Journal/conference name.

    • 73 |
    • jnl_top_25p: 0/1 variable of whether the journal belongs to the top 25% in terms of average cites.

    • 74 |
    • jnl_top_5p: 0/1 variable of whether the journal belongs to the top 5% in terms of average cites.

    • 75 |
    76 |
    77 |

    Source

    78 |

    The source is Microsoft Academic Graph (see reference).

    79 |
    80 |
    81 |

    References

    82 |

    Arnab Sinha, Zhihong Shen, Yang Song, Hao Ma, Darrin Eide, Bo-June (Paul) Hsu, and Kuansan Wang. 2015. An Overview of Microsoft Academic Service (MAS) and Applications. In Proceedings of the 24th International Conference on World Wide Web (WWW '15 Companion). ACM, New York, NY, USA, 243-246.

    83 |
    84 | 85 |
    86 | 89 |
    90 | 91 | 92 |
    95 | 96 |
    97 |

    Site built with pkgdown 2.0.7.

    98 |
    99 | 100 |
    101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /docs/sitemap.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | /404.html 5 | 6 | 7 | /articles/Exporting_graphs.html 8 | 9 | 10 | /articles/fplot_walkthrough.html 11 | 12 | 13 | /articles/index.html 14 | 15 | 16 | /authors.html 17 | 18 | 19 | /index.html 20 | 21 | 22 | /news/index.html 23 | 24 | 25 | /reference/export_graph_start.html 26 | 27 | 28 | /reference/fit.off.html 29 | 30 | 31 | /reference/fplot-package.html 32 | 33 | 34 | /reference/index.html 35 | 36 | 37 | /reference/pdf_fit.html 38 | 39 | 40 | /reference/plot_box.html 41 | 42 | 43 | /reference/plot_distr.html 44 | 45 | 46 | /reference/plot_lines.html 47 | 48 | 49 | /reference/png_fit.html 50 | 51 | 52 | /reference/setFplot_dict.html 53 | 54 | 55 | /reference/setFplot_distr.html 56 | 57 | 58 | /reference/setFplot_page.html 59 | 60 | 61 | /reference/us_pub_econ.html 62 | 63 | 64 | -------------------------------------------------------------------------------- /fplot.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 4 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageUseDevtools: Yes 20 | PackageInstallArgs: --no-multiarch --with-keep.source 21 | PackageCheckArgs: --as-cran 22 | PackageRoxygenize: rd 23 | -------------------------------------------------------------------------------- /man/export_graph_start.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/miscfuns.R 3 | \name{export_graph_start} 4 | \alias{export_graph_start} 5 | \alias{export_graph_end} 6 | \title{Graph export with garanteed text size} 7 | \usage{ 8 | export_graph_start( 9 | file, 10 | pt = 10, 11 | width = 1, 12 | height, 13 | w2h = 1.75, 14 | h2w, 15 | sideways = FALSE, 16 | res = 300, 17 | type = NULL, 18 | ... 19 | ) 20 | 21 | export_graph_end() 22 | } 23 | \arguments{ 24 | \item{file}{Character scalar. The name of the file in which to save the graph. 25 | If the argument type is \code{NULL}, the type of file is deduced from the extension. 26 | If your file extension is different from your file type, you need to use the 27 | argument \code{type}.} 28 | 29 | \item{pt}{The size of the text, in pt, once the figure is inserted in your final document. 30 | The default is 10. This means that all text appearing in the plot with \code{cex = 1} 31 | will appear with 10pt-sized fonts in your document.} 32 | 33 | \item{width}{The width of the graph, expressed in percentage of the width of 34 | the body-text of the document in which it will be inserted. Default is 1, which means 35 | that the graph will take 100\% of the text width. It can also be equal to a character 36 | of the type \code{"100\%"} or \code{"80\%"}. Alternatively, the following units 37 | are valid. Relative sizes: \code{"pw"} (page width), \code{"tw"} (text width), 38 | \code{"ph"} (page height), \code{"th"} (text height). 39 | Absolute sizes: \code{"in"}, \code{"cm"}, and \code{"px"}.} 40 | 41 | \item{height}{Numeric between 0 and 1 or character scalar. The height of the graph, 42 | expressed in percentage of the height of the body-text of the document in which it 43 | will be inserted. Default is missing, and the height is determined by the other 44 | argument \code{w2h}. This argument should range between 0 and 1. It can also be 45 | equal to a character of the type \code{"100\%"} or \code{"80\%"}. Alternatively, the 46 | following units are valid. Relative sizes: \code{"pw"} (page width), \code{"tw"} 47 | (text width), \code{"ph"} (page height), \code{"th"} (text height). Absolute 48 | sizes: \code{"in"}, \code{"cm"}, and \code{"px"}.} 49 | 50 | \item{w2h}{Numeric scalar. Used to determine the height of the figure based on 51 | the width. By default it is equal to \code{1.75} which means that the graph 52 | will be 1.75 larger than tall. Note that when argument \code{sideways = TRUE}, 53 | the default for the height becomes \verb{90\%}.} 54 | 55 | \item{h2w}{Numeric scalar, default is missing. Used to determine the aspectr ratio of the figure.} 56 | 57 | \item{sideways}{Logical, defaults to \code{FALSE}. If the figure will be placed in 58 | landscape in the final document, then \code{sideways} should be equal to \code{TRUE}. 59 | If TRUE, then the argument \code{width} now refers to the height of the text, and the 60 | argument \code{height} to its width.} 61 | 62 | \item{res}{Numeric, the resolution in ppi. Default is 300.} 63 | 64 | \item{type}{Character scalar, default is \code{NULL}. The type of file to be created. 65 | If \code{NULL}, the default, then the type of file is deduced from the extension.} 66 | 67 | \item{...}{Other arguments to be passed to \code{\link[grDevices:png]{bmp}}, 68 | \code{\link[grDevices]{png}}, \code{\link[grDevices:png]{jpeg}}, or 69 | \code{\link[grDevices:png]{tiff}}. For example: \code{antialias}, \code{bg}, etc.} 70 | } 71 | \value{ 72 | These functions do not return anything in R. \code{export_graph_start} creates a 73 | file linked to the R graphics engine, in which subsequent plots are saved. 74 | \code{export_graph_end} closes the connection and the file. 75 | } 76 | \description{ 77 | This function facilitates graph exportation by taking into account the final 78 | destination of the graph (typically a document) and allowing the user to use 79 | point size, an intuitive unit 80 | in written documents, as the graph scaler. Once located in the final document, the text of the graph 81 | at the default size will be at the defined point size. 82 | } 83 | \details{ 84 | To export a ggplot2 graph, remember that you need to \strong{print} it! 85 | 86 | \if{html}{\out{
    }}\preformatted{library(ggplot2) 87 | data = data.frame(x = c(1, 2, 3, 4, 5), y = c(2, 4, 6, 8, 10)) 88 | 89 | # NOT GOOD 90 | export_graph_start("test.pdf") 91 | ggplot(data, aes(x, y)) + 92 | geom_point(color = "#54BF98") + 93 | geom_line(color = "#d34661") 94 | export_graph_end() 95 | 96 | # GOOD 97 | my_graph = ggplot(data, aes(x, y)) + 98 | geom_point(color = "#54BF98") + 99 | geom_line(color = "#d34661") 100 | 101 | export_graph_start("test.pdf") 102 | print(my_graph) 103 | export_graph_end() 104 | }\if{html}{\out{
    }} 105 | 106 | When the function \code{export_graph_end()} is called, the resulting exported graph 107 | is displayed in the Viewer. The viewer function is found with 108 | \code{getOption("viewer")} and should work on RStudio and VSCode (with the R extension). 109 | } 110 | \section{Functions}{ 111 | \itemize{ 112 | \item \code{export_graph_end()}: Ends the connection to the current export and creates the file. 113 | 114 | }} 115 | \section{Setting the page size}{ 116 | 117 | 118 | You can set the page size with the function \code{\link[fplot]{setFplot_page}}, 119 | which defines the size of the page and its margins to deduce the size of the body 120 | of the text in which the figures will be inserted. By default the page is considered 121 | to be US-letter with \emph{normal} margins (not too big nor thin). 122 | 123 | It is important to set the page size appropriately to have a final plotting-text size 124 | guaranteed once the figure is inserted in the document. 125 | } 126 | 127 | \examples{ 128 | 129 | tmpFile = file.path(tempdir(), "png_examples.pdf") 130 | 131 | # we start the exportation 132 | export_graph_start(tmpFile, pt = 8) 133 | 134 | plot(1, 1, type = "n", ann = FALSE) 135 | text(1, 1, "This text will be displayed in 8pt.") 136 | 137 | # the line below closes the connection and displays the 138 | # graph in the viewer pane if appropritate 139 | export_graph_end() 140 | 141 | } 142 | \seealso{ 143 | The tool to set the page size and the exporting defaults: \code{\link[fplot]{setFplot_page}}. 144 | Exporting functions \code{\link[fplot]{pdf_fit}}, \code{\link[fplot:pdf_fit]{png_fit}}, 145 | \code{\link[fplot:pdf_fit]{jpeg_fit}}. 146 | 147 | The functions \code{\link[=export_graph_start]{export_graph_start()}} and \code{\link[=export_graph_end]{export_graph_end()}} provide similar features. 148 | } 149 | \author{ 150 | Laurent Berge 151 | } 152 | -------------------------------------------------------------------------------- /man/figures/conditional_iris_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/man/figures/conditional_iris_1.png -------------------------------------------------------------------------------- /man/figures/conditional_iris_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/man/figures/conditional_iris_2.png -------------------------------------------------------------------------------- /man/figures/conditional_iris_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/man/figures/conditional_iris_3.png -------------------------------------------------------------------------------- /man/figures/conditional_pub_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/man/figures/conditional_pub_1.png -------------------------------------------------------------------------------- /man/figures/conditional_pub_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/man/figures/conditional_pub_2.png -------------------------------------------------------------------------------- /man/figures/conditional_pub_3_bis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/man/figures/conditional_pub_3_bis.png -------------------------------------------------------------------------------- /man/figures/conditional_trade_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/man/figures/conditional_trade_1.png -------------------------------------------------------------------------------- /man/figures/conditional_trade_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/man/figures/conditional_trade_2.png -------------------------------------------------------------------------------- /man/figures/cumul_iris.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/man/figures/cumul_iris.png -------------------------------------------------------------------------------- /man/figures/cumul_pub.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/man/figures/cumul_pub.png -------------------------------------------------------------------------------- /man/figures/cumul_trade.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/man/figures/cumul_trade.png -------------------------------------------------------------------------------- /man/figures/regular_iris.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/man/figures/regular_iris.png -------------------------------------------------------------------------------- /man/figures/regular_pub.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/man/figures/regular_pub.png -------------------------------------------------------------------------------- /man/figures/regular_trade.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/man/figures/regular_trade.png -------------------------------------------------------------------------------- /man/figures/weighted_conditional_trade_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/man/figures/weighted_conditional_trade_1.png -------------------------------------------------------------------------------- /man/figures/weighted_conditional_trade_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/man/figures/weighted_conditional_trade_2.png -------------------------------------------------------------------------------- /man/figures/weighted_pub_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/man/figures/weighted_pub_1.png -------------------------------------------------------------------------------- /man/figures/weighted_pub_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/man/figures/weighted_pub_2.png -------------------------------------------------------------------------------- /man/figures/weighted_stacked_pub.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/man/figures/weighted_stacked_pub.png -------------------------------------------------------------------------------- /man/figures/weighted_stacked_trade.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/man/figures/weighted_stacked_trade.png -------------------------------------------------------------------------------- /man/figures/weighted_trade_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/man/figures/weighted_trade_1.png -------------------------------------------------------------------------------- /man/figures/weighted_trade_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/man/figures/weighted_trade_2.png -------------------------------------------------------------------------------- /man/fit.off.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/miscfuns.R 3 | \name{fit.off} 4 | \alias{fit.off} 5 | \title{Closes the current plotting device and shows the result in the viewer} 6 | \usage{ 7 | fit.off() 8 | } 9 | \value{ 10 | This function does not return anything in R. It closes the connection between the 11 | R graphics engine and a file that has been defined via one of the functions: 12 | pdf_fitpng_fit 13 | } 14 | \description{ 15 | \emph{This function is deprecated: Please use the functions \code{\link[=export_graph_start]{export_graph_start()}} 16 | and \code{\link[=export_graph_end]{export_graph_end()}} instead.} 17 | } 18 | \details{ 19 | To be used in combination with \code{\link[fplot]{pdf_fit}} or \code{\link[fplot]{png_fit}} 20 | when exporting images. It performs exactly the same thing as \code{dev.off()} but additionaly 21 | shows the resulting graph in the viewer pane provided you're using RStudio. 22 | 23 | To view the results of PDF exports, the function \code{pdf_convert} from package \code{pdftools} 24 | is used to convert the PDF files into images -- so you need to have installed 25 | \code{pdftools} to make it work. 26 | 27 | In PDFs, only the first page will be viewed. 28 | } 29 | \examples{ 30 | 31 | # Exportation example 32 | # The functions pdf_fit, png_fit, etc, guarantee the right 33 | # point size of the texts present in the graph. 34 | # But you must give the exact size the graph will take in your final document. 35 | # => first use the function setFplot_page, default is: 36 | # setFplot_page(page = "us", margins = "normal") 37 | # By default the graph takes 100\% of the text width 38 | 39 | data(us_pub_econ) 40 | 41 | tmpFile = file.path(tempdir(), "DISTR -- institutions.png") 42 | 43 | png_fit(tmpFile) 44 | plot_distr(~institution, us_pub_econ) 45 | fit.off() 46 | 47 | # What's the consequence of increasing the point size of the text? 48 | png_fit(tmpFile, pt = 15) 49 | plot_distr(~institution, us_pub_econ) 50 | fit.off() 51 | 52 | 53 | } 54 | \seealso{ 55 | The tool to set the page size and the exporting defaults: \code{\link[fplot]{setFplot_page}}. 56 | Exporting functions \code{\link[fplot]{pdf_fit}}, \code{\link[fplot:pdf_fit]{png_fit}}, 57 | \code{\link[fplot:pdf_fit]{jpeg_fit}}. 58 | 59 | The functions \code{\link[=export_graph_start]{export_graph_start()}} and \code{\link[=export_graph_end]{export_graph_end()}} provide similar features. 60 | } 61 | \author{ 62 | Laurent Berge 63 | } 64 | -------------------------------------------------------------------------------- /man/fplot-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fplot.R 3 | \docType{package} 4 | \name{fplot-package} 5 | \alias{fplot} 6 | \alias{fplot-package} 7 | \title{Aggregate/conditional graphs and automatic layout using formulas} 8 | \description{ 9 | \pkg{fplot} provides automatic plotting of common graphs (distributions, lines, bar plots and boxplots). The syntax uses formulas, allowing aggregate/conditional/weighted graphs with minimum efforts. The many arguments are automatically adjusted to the data in order to provide the nicest and most meaningful graphs. 10 | } 11 | \details{ 12 | The core functions is \code{\link[fplot]{plot_distr}} to draw distributions. 13 | Two other graphical functions are provided for convenience: \code{\link[fplot]{plot_lines}} to represent the (usually temporal) evolution of some variables, and \code{\link[fplot]{plot_box}} to easily represent conditional boxplots. 14 | 15 | It also integrates tools to easily export graphs: \code{\link[fplot]{pdf_fit}} and \code{\link[fplot]{png_fit}}. In these functions, instead of providing the size of the graphics, you instead give the point size that the text should have in the final document--because an exported graph usually ends up in a document. You can set the size of your document with the function \code{\link[fplot]{setFplot_page}}. If you use the function \code{\link[fplot]{fit.off}} to close the connection, you will also see how the export looks like in the Viewer pane. 16 | } 17 | \author{ 18 | \strong{Maintainer}: Laurent Berge \email{laurent.berge@u-bordeaux.fr} 19 | 20 | } 21 | -------------------------------------------------------------------------------- /man/pdf_fit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/miscfuns.R 3 | \name{pdf_fit} 4 | \alias{pdf_fit} 5 | \title{PDF export with guaranteed text size} 6 | \usage{ 7 | pdf_fit( 8 | file, 9 | pt = 10, 10 | width = 1, 11 | height, 12 | w2h = 1.75, 13 | h2w, 14 | sideways = FALSE, 15 | ... 16 | ) 17 | } 18 | \arguments{ 19 | \item{file}{The name of the file to which export the figure.} 20 | 21 | \item{pt}{The size of the text, in pt, once the figure is inserted in your final document. 22 | The default is 10. This means that all text appearing in the plot with \code{cex = 1} 23 | will appear with 10pt-sized fonts in your document.} 24 | 25 | \item{width}{The width of the graph, expressed in percentage of the width of 26 | the body-text of the document in which it will be inserted. Default is 1, which means 27 | that the graph will take 100\% of the text width. It can also be equal to a character 28 | of the type \code{"100\%"} or \code{"80\%"}. Alternatively, the following units 29 | are valid. Relative sizes: \code{"pw"} (page width), \code{"tw"} (text width), 30 | \code{"ph"} (page height), \code{"th"} (text height). 31 | Absolute sizes: \code{"in"}, \code{"cm"}, and \code{"px"}.} 32 | 33 | \item{height}{Numeric between 0 and 1 or character scalar. The height of the graph, 34 | expressed in percentage of the height of the body-text of the document in which it 35 | will be inserted. Default is missing, and the height is determined by the other 36 | argument \code{w2h}. This argument should range between 0 and 1. It can also be 37 | equal to a character of the type \code{"100\%"} or \code{"80\%"}. Alternatively, the 38 | following units are valid. Relative sizes: \code{"pw"} (page width), \code{"tw"} 39 | (text width), \code{"ph"} (page height), \code{"th"} (text height). Absolute 40 | sizes: \code{"in"}, \code{"cm"}, and \code{"px"}.} 41 | 42 | \item{w2h}{Numeric scalar. Used to determine the height of the figure based on 43 | the width. By default it is equal to \code{1.75} which means that the graph 44 | will be 1.75 larger than tall. Note that when argument \code{sideways = TRUE}, 45 | the default for the height becomes \verb{90\%}.} 46 | 47 | \item{h2w}{Numeric scalar, default is missing. Used to determine the aspectr ratio of the figure.} 48 | 49 | \item{sideways}{Logical, defaults to \code{FALSE}. If the figure will be placed in 50 | landscape in the final document, then \code{sideways} should be equal to \code{TRUE}. 51 | If TRUE, then the argument \code{width} now refers to the height of the text, and the 52 | argument \code{height} to its width.} 53 | 54 | \item{...}{Other arguments to be passed to \code{\link[grDevices]{pdf}}.} 55 | } 56 | \value{ 57 | This function does not return anything. It connects the output of the R graphics 58 | engine to a file. 59 | } 60 | \description{ 61 | (\emph{This function is deprecated: Please use the functions \code{\link[=export_graph_start]{export_graph_start()}} 62 | and \code{\link[=export_graph_end]{export_graph_end()}} instead.}) 63 | This function is an alternative to \code{\link[grDevices]{pdf}}, it makes it easy 64 | to export figures of appropriate size that should end up in a document. Instead 65 | of providing the height and width of the figure, you provide the fraction of the 66 | text-width the figure should take, and the target font-size at which the plotting 67 | text should be rendered. The size of the plotting text, once the figure is 68 | in the final document, is guaranteed. 69 | } 70 | \details{ 71 | If you use \code{\link[fplot]{fit.off}} instead of \code{dev.off} to close the graph, 72 | the resulting graph will be displayed in the viewer pane. So you don't have to open 73 | the document to see how it looks. 74 | 75 | To export a ggplot2 graph, remember that you need to \strong{print} it! 76 | 77 | \if{html}{\out{
    }}\preformatted{library(ggplot2) 78 | data = data.frame(x = c(1, 2, 3, 4, 5), y = c(2, 4, 6, 8, 10)) 79 | 80 | # NOT GOOD 81 | pdf_fit("test.pdf") 82 | ggplot(data, aes(x, y)) + 83 | geom_point(color = "#54BF98") + 84 | geom_line(color = "#d34661") 85 | fit.off() 86 | 87 | # GOOD 88 | my_graph = ggplot(data, aes(x, y)) + 89 | geom_point(color = "#54BF98") + 90 | geom_line(color = "#d34661") 91 | 92 | pdf_fit("test.pdf") 93 | print(my_graph) 94 | fit.off() 95 | }\if{html}{\out{
    }} 96 | } 97 | \section{Setting the page size}{ 98 | 99 | 100 | You can set the page size with the function \code{\link[fplot]{setFplot_page}}, 101 | which defines the size of the page and its margins to deduce the size of the body 102 | of the text in which the figures will be inserted. By default the page is considered 103 | to be US-letter with \emph{normal} margins (not too big nor thin). 104 | 105 | It is important to set the page size appropriately to have a final plotting-text size 106 | guaranteed once the figure is inserted in the document. 107 | } 108 | 109 | \examples{ 110 | 111 | 112 | # This function creates figures made to be inserted 113 | # in a Latex document (US-letter with "normal" margins) 114 | # By default, the figures should take 100\% of the 115 | # text width. If so, the size of the text in the figures 116 | # will be exact. 117 | 118 | # You need pdftools and knitr to display PDFs in the viewer pane with fit.off 119 | if(require(pdftools) && require(knitr)){ 120 | 121 | tmpFile = file.path(tempdir(), "pdf_examples.pdf") 122 | 123 | pdf_fit(tmpFile, pt = 8) 124 | plot(1, 1, type = "n", ann = FALSE) 125 | text(1, 1, "This text will be displayed in 8pt.") 126 | fit.off() 127 | 128 | pdf_fit(tmpFile, pt = 12) 129 | plot(1, 1, type = "n", ann = FALSE) 130 | text(1, 1, "This text will be displayed in 12pt.") 131 | fit.off() 132 | 133 | pdf_fit(tmpFile, pt = 12, sideways = TRUE) 134 | plot(1, 1, type = "n", ann = FALSE) 135 | text(1, 1, "This text will be displayed in 12pt if in sideways.") 136 | fit.off() 137 | 138 | # If we reduce the end plot width but keep font size constant 139 | # this will lead to a very big font as compared to the plot 140 | pdf_fit(tmpFile, pt = 8, width = "50\%") 141 | plot(1, 1, type = "n", ann = FALSE) 142 | text(1, 1, "This text will be displayed in 8pt\nif in 50\% of the text width.") 143 | fit.off() 144 | } 145 | 146 | 147 | 148 | 149 | 150 | 151 | } 152 | \seealso{ 153 | To set the geometry and the defaults: \code{\link[fplot]{setFplot_page}}. 154 | To close the graph and display it on the viewer pane: \code{\link[fplot]{fit.off}}. 155 | } 156 | \author{ 157 | Laurent Berge 158 | } 159 | -------------------------------------------------------------------------------- /man/plot_box.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/visualization.R 3 | \name{plot_box} 4 | \alias{plot_box} 5 | \title{Boxplots with possibly moderators} 6 | \usage{ 7 | plot_box( 8 | fml, 9 | data, 10 | case, 11 | moderator, 12 | inCol, 13 | outCol = "black", 14 | density = -1, 15 | lty = 1, 16 | pch = 18, 17 | addLegend = TRUE, 18 | legend_options = list(), 19 | lwd = 2, 20 | outlier, 21 | dict = NULL, 22 | dict_case, 23 | dict_moderator, 24 | order_case, 25 | order_moderator, 26 | addMean, 27 | mean.col = "darkred", 28 | mean.pch = 18, 29 | mean.cex = 2, 30 | mod.title = TRUE, 31 | labels.tilted, 32 | trunc = 20, 33 | trunc.method = "auto", 34 | line.max, 35 | ... 36 | ) 37 | } 38 | \arguments{ 39 | \item{fml}{A numeric vector or a formula of the type: \code{vars ~ moderator_1 | moderator_2}. Note that if a formula is provided then the argument \sQuote{data} must be provided. You can plot several variables, if you don't want a moderator, use 1 instead: e.g. \code{plot_box(Petal.Width +Petal.Length ~ 1, iris)}. You can plot all numeric variables from a data set using \code{"."}: \code{plot_box(. ~ 1, iris)}.} 40 | 41 | \item{data}{A data.frame/data.table containing the relevant information.} 42 | 43 | \item{case}{When argument fml is a vector, this argument can receive a vector of cases.} 44 | 45 | \item{moderator}{When argument fml is a vector, this argument can receive a vector of moderators.} 46 | 47 | \item{inCol}{A vector of colors that will be used for within the boxes.} 48 | 49 | \item{outCol}{The color of the outer box. Default is black.} 50 | 51 | \item{density}{The density of lines within the boxes. By default it is equal to -1, which means the boxes are filled with color.} 52 | 53 | \item{lty}{The type of lines for the border of the boxes. Default is 1 (solid line).} 54 | 55 | \item{pch}{The patch of the outliers. Default is 18.} 56 | 57 | \item{addLegend}{Default is \code{TRUE}. Should a legend be added at the top of the graph is there is more than one moderator?} 58 | 59 | \item{legend_options}{A list. Other options to be passed to \code{legend} which 60 | concerns the legend for the moderator.} 61 | 62 | \item{lwd}{The width of the lines making the boxes. Default is 2.} 63 | 64 | \item{outlier}{Default is \code{TRUE}. Should the outliers be displayed?} 65 | 66 | \item{dict}{A dictionnary to rename the variables names in the axes and legend. 67 | Should be a named vector. By default it s the value of \code{getFplot_dict()}, 68 | which you can set with the function \code{\link[fplot]{setFplot_dict}}.} 69 | 70 | \item{dict_case}{A named character vector. If provided, it changes the values of the variable \sQuote{case} to the ones contained in the vector \code{dict_case}. Example: I want to change my variable named "a" to "Australia" and "b" to "Brazil", then I used \code{dict=c(a="Australia",b="Brazil")}.} 71 | 72 | \item{dict_moderator}{A named character vector. If provided, it changes the values of the variable \sQuote{moderator} to the ones contained in the vector \code{dict_moderator}. Example: I want to change my variable named "a" to "Australia" and "b" to "Brazil", then I used \code{dict=c(a="Australia",b="Brazil")}.} 73 | 74 | \item{order_case}{Character vector. This element is used if the user wants the \sQuote{case} values to be ordered in a certain way. This should be a regular expression (see \code{\link[base]{regex}} help for more info). There can be more than one regular expression. The variables satisfying the first regular expression will be placed first, then the order follows the sequence of regular expressions.} 75 | 76 | \item{order_moderator}{Character vector. This element is used if the user wants the \sQuote{moderator} values to be ordered in a certain way. This should be a regular expression (see \code{\link[base]{regex}} help for more info). There can be more than one regular expression. The variables satisfying the first regular expression will be placed first, then the order follows the sequence of regular expressions.} 77 | 78 | \item{addMean}{Whether to add the average for each boxplot. Default is true.} 79 | 80 | \item{mean.col}{The color of the mean. Default is darkred.} 81 | 82 | \item{mean.pch}{The patch of the mean, default is 18.} 83 | 84 | \item{mean.cex}{The cex of the mean, default is 2.} 85 | 86 | \item{mod.title}{Character scalar. The title of the legend in case there is a 87 | moderator. You can set it to \code{TRUE} (the default) to display the moderator 88 | name. To display no title, set it to \code{NULL} or \code{FALSE}.} 89 | 90 | \item{labels.tilted}{Whether there should be tilted labels. Default is \code{FALSE} 91 | except when the data is split by moderators (see \code{mod.method}).} 92 | 93 | \item{trunc}{If the main variable is a character, its values are truncaded to 94 | \code{trunc} characters. Default is 20. You can set the truncation method with 95 | the argument \code{trunc.method}.} 96 | 97 | \item{trunc.method}{If the elements of the x-axis need to be truncated, this 98 | is the truncation method. It can be "auto", "right" or "mid".} 99 | 100 | \item{line.max}{Option for the x-axis, how far should the labels go. Default is 1 for normal labels, 2 for tilted labels.} 101 | 102 | \item{...}{Other parameters to be passed to \code{plot}.} 103 | } 104 | \value{ 105 | Invisibly returns the coordinates of the x-axis. 106 | } 107 | \description{ 108 | This function allows to draw a boxplot, with possibly separating different moderators. 109 | } 110 | \examples{ 111 | 112 | # Simple iris boxplot 113 | plot(1:10) 114 | 115 | # All numeric variables 116 | plot_box(. ~ 1, iris) 117 | 118 | # All numeric variable / splitting by species 119 | plot_box(. ~ Species, iris) 120 | 121 | # idem but with renaming 122 | plot_box(. ~ Species, iris, dict = c(Species="Iris species", 123 | setosa="SETOSA", Petal.Width="Width (Petal)")) 124 | 125 | # Now using two moderators 126 | base = iris 127 | base$period = sample(1:4, 150, TRUE) 128 | 129 | plot_box(Petal.Length ~ period | Species, base) 130 | 131 | 132 | 133 | 134 | 135 | } 136 | \author{ 137 | Laurent Berge 138 | } 139 | -------------------------------------------------------------------------------- /man/plot_distr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/visualization.R 3 | \name{plot_distr} 4 | \alias{plot_distr} 5 | \title{Plot distributions, possibly conditional} 6 | \usage{ 7 | plot_distr( 8 | fml, 9 | data, 10 | moderator, 11 | weight, 12 | sorted, 13 | log, 14 | nbins, 15 | bin.size, 16 | legend_options = list(), 17 | top, 18 | yaxis.show = TRUE, 19 | yaxis.num, 20 | col, 21 | border = "black", 22 | mod.method, 23 | within, 24 | total, 25 | mod.select, 26 | mod.NA = FALSE, 27 | at_5, 28 | labels.tilted, 29 | other, 30 | cumul = FALSE, 31 | plot = TRUE, 32 | sep, 33 | centered = TRUE, 34 | weight.fun, 35 | int.categorical, 36 | dict = NULL, 37 | mod.title = TRUE, 38 | labels.angle, 39 | cex.axis, 40 | trunc = 20, 41 | trunc.method = "auto", 42 | ... 43 | ) 44 | } 45 | \arguments{ 46 | \item{fml}{A formula or a vector. If a formula, it must be of the type: 47 | \code{weights ~ var | moderator}. If there are no moderator nor weights, you 48 | can use directly a vector, or use a one-sided formula \code{fml = ~var}. You 49 | can use multiple variables as weights, if so, you cannot use moderators at the 50 | same time. See examples.} 51 | 52 | \item{data}{A data.frame: data set containing the variables in the formula.} 53 | 54 | \item{moderator}{Optional, only if argument \code{fml} is a vector. A vector 55 | of moderators.} 56 | 57 | \item{weight}{Optional, only if argument \code{fml} is a vector. A vector of 58 | (positive) weights.} 59 | 60 | \item{sorted}{Logical: should the first elements displayed be the most frequent? 61 | By default this is the case except for numeric values put to log or to integers.} 62 | 63 | \item{log}{Logical, only used when the data is numeric. If \code{TRUE}, then 64 | the data is put to logarithm beforehand. By default numeric values are put to 65 | log if the log variation exceeds 3.} 66 | 67 | \item{nbins}{Maximum number of items displayed. The default depends on the number 68 | of moderator cases. When there is no moderator, the default is 15, augmented 69 | to 20 if there are less than 20 cases.} 70 | 71 | \item{bin.size}{Only used for numeric values. If provided, it creates bins of 72 | observations of size \code{bin.size}. It creates bins by default for numeric non-integer data.} 73 | 74 | \item{legend_options}{A list. Other options to be passed to \code{legend} which 75 | concerns the legend for the moderator.} 76 | 77 | \item{top}{What to display on the top of the bars. Can be equal to "frac" (for 78 | shares), "nb" or "none". The default depends on the type of the plot. To disable 79 | it you can also set it to \code{FALSE} or the empty string.} 80 | 81 | \item{yaxis.show}{Whether the y-axis should be displayed, default is \code{TRUE}.} 82 | 83 | \item{yaxis.num}{Whether the y-axis should display regular numbers instead of 84 | frequencies in percentage points. By default it shows numbers only when the data 85 | is weighted with a different function than the sum. For conditionnal distributions, 86 | a numeric y-axis can be displayed only when \code{mod.method = "sideTotal"}, 87 | \code{mod.method = "splitTotal"} or \code{mod.method = "stack"}, since for the 88 | within distributions it does not make sense (because the data is rescaled for each moderator).} 89 | 90 | \item{col}{A vector of colors, default is close to paired. You can also use \dQuote{set1} 91 | or \dQuote{paired}.} 92 | 93 | \item{border}{Outer color of the bars. Defaults is \code{"black"}. Use \code{NA} 94 | to remove the borders.} 95 | 96 | \item{mod.method}{A character scalar: either i) \dQuote{split}, the default for 97 | categorical data, ii) \dQuote{side}, the default for data in logarithmic form 98 | or numeric data, or iii) \dQuote{stack}. This is only used when there is more 99 | ù than one moderator. If \code{"split"}: there is one separate histogram for each 100 | moderator case. If \code{"side"}: moderators are represented side by side for 101 | each value of the variable. If \code{"stack"}: the bars of the moderators are 102 | stacked onto each other, the bar heights representing the distribution in the 103 | total population. You can use the other arguments \code{within} and \code{total} 104 | to say whether the distributions should be within each moderator or over the 105 | total distribution.} 106 | 107 | \item{within}{Logical, default is missing. Whether the distributions should be 108 | scaled to reflect the distribution within each moderator value. By default it 109 | is \code{TRUE} if \code{mod.method} is different from \code{"stack"}.} 110 | 111 | \item{total}{Logical, default is missing. Whether the distributions should be 112 | scaled to reflect the total distribution (and not the distribution within each 113 | moderator value). By default it is \code{TRUE} only if \code{mod.method="stack"}.} 114 | 115 | \item{mod.select}{Which moderators to select. By default the top 3 moderators 116 | in terms of frequency (or in terms of weight value if there's a weight) are displayed. 117 | If provided, it must be a vector of moderator values whose length cannot be greater 118 | than 5. Alternatively, you can put an integer between 1 and 5. This argument 119 | also accepts regular expressions.} 120 | 121 | \item{mod.NA}{Logical, default is \code{FALSE}. If \code{TRUE}, and if the moderator 122 | contains \code{NA} values, all \code{NA} values from the moderator will be treated 123 | as a regular case: allows to display the distribution for missing values.} 124 | 125 | \item{at_5}{Equal to \code{FALSE}, \code{"roman"} or \code{"line"}. When plotting 126 | categorical variables, adds a small Roman number under every 5 bars 127 | (\code{at_5 = "roman"}), or draws a thick axis line every 5 bars (\code{at_5 = "line"}). 128 | Helps to get the rank of the bars. The default depends on the type of data -- 129 | Not implemented when there is a moderator.} 130 | 131 | \item{labels.tilted}{Whether there should be tilted labels. Default is \code{FALSE} 132 | except when the data is split by moderators (see \code{mod.method}).} 133 | 134 | \item{other}{Logical. Should there be a last column counting for the observations 135 | not displayed? Default is \code{TRUE} except when the data is split.} 136 | 137 | \item{cumul}{Logical, default is \code{FALSE}. If \code{TRUE}, then the cumulative 138 | distribution is plotted.} 139 | 140 | \item{plot}{Logical, default is \code{TRUE}. If \code{FALSE} nothing is plotted, 141 | only the data is returned.} 142 | 143 | \item{sep}{Positive number. The separation space between the bars. The scale 144 | depends on the type of graph.} 145 | 146 | \item{centered}{Logical, default is \code{TRUE}. For numeric data only and when 147 | \code{sorted=FALSE}, whether the histogram should be centered on the mode.} 148 | 149 | \item{weight.fun}{A function, by default it is \code{sum}. Aggregate function 150 | to be applied to the weight with respect to variable and the moderator. See examples.} 151 | 152 | \item{int.categorical}{Logical. Whether integers should be treated as categorical 153 | variables. By default they are treated as categorical only when their range is 154 | small (i.e. smaller than 1000).} 155 | 156 | \item{dict}{A dictionnary to rename the variables names in the axes and legend. 157 | Should be a named vector. By default it s the value of \code{getFplot_dict()}, 158 | which you can set with the function \code{\link[fplot]{setFplot_dict}}.} 159 | 160 | \item{mod.title}{Character scalar. The title of the legend in case there is a 161 | moderator. You can set it to \code{TRUE} (the default) to display the moderator 162 | name. To display no title, set it to \code{NULL} or \code{FALSE}.} 163 | 164 | \item{labels.angle}{Only if the labels of the x-axis are tilted. The angle of the tilt.} 165 | 166 | \item{cex.axis}{Cex value to be passed to biased labels. By defaults, it finds 167 | automatically the right value.} 168 | 169 | \item{trunc}{If the main variable is a character, its values are truncaded to 170 | \code{trunc} characters. Default is 20. You can set the truncation method with 171 | the argument \code{trunc.method}.} 172 | 173 | \item{trunc.method}{If the elements of the x-axis need to be truncated, this 174 | is the truncation method. It can be "auto", "right" or "mid".} 175 | 176 | \item{...}{Other elements to be passed to plot.} 177 | } 178 | \value{ 179 | This function returns \emph{invisibly} the output data.table containing the processed data 180 | used for plotting. With the argument \code{plot = FALSE}, only the data is returned. 181 | } 182 | \description{ 183 | This function plots distributions of items (a bit like an histogram) which can 184 | be easily conditioned over. 185 | } 186 | \details{ 187 | Most default values can be modified with the function \code{\link[fplot]{setFplot_distr}}. 188 | } 189 | \examples{ 190 | 191 | # Data on publications from U.S. institutions 192 | data(us_pub_econ) 193 | 194 | # 0) Let's set a dictionary for a better display of variables 195 | setFplot_dict(c(institution = "U.S. Institution", jnl_top_25p = "Top 25\% Pub.", 196 | jnl_top_5p = "Top 5\% Pub.", Frequency = "Publications")) 197 | 198 | # 1) Let's plot the distribution of publications by institutions: 199 | plot_distr(~institution, us_pub_econ) 200 | 201 | # When there is only the variable, you can use a vector instead: 202 | plot_distr(us_pub_econ$institution) 203 | 204 | # 2) Now the production of institution weighted by journal quality 205 | plot_distr(jnl_top_5p ~ institution, us_pub_econ) 206 | 207 | # You can plot several variables: 208 | plot_distr(1 + jnl_top_25p + jnl_top_5p ~ institution, us_pub_econ) 209 | 210 | # 3) Let's plot the journal distribution for the top 3 institutions 211 | 212 | # We can get the data from the previous graph 213 | graph_data = plot_distr(jnl_top_5p ~ institution, us_pub_econ, plot = FALSE) 214 | # And then select the top universities 215 | top3_instit = graph_data$x[1:3] 216 | top5_instit = graph_data$x[1:5] # we'll use it later 217 | 218 | # Now the distribution of journals 219 | plot_distr(~ journal | institution, us_pub_econ[institution \%in\% top3_instit]) 220 | # Alternatively, you can use the argument mod.select: 221 | plot_distr(~ journal | institution, us_pub_econ, mod.select = top3_instit) 222 | 223 | # 3') Same graph as before with "other" column, 5 institutions 224 | plot_distr(~ journal | institution, us_pub_econ, 225 | mod.select = top5_instit, other = TRUE) 226 | 227 | # 228 | # Example with continuous data 229 | # 230 | 231 | # regular histogram 232 | plot_distr(iris$Sepal.Length) 233 | 234 | # now splitting by species: 235 | plot_distr(~ Sepal.Length | Species, iris) 236 | 237 | # idem but the three distr. are separated: 238 | plot_distr(~ Sepal.Length | Species, iris, mod.method = "split") 239 | 240 | # Now the three are stacked 241 | plot_distr(~ Sepal.Length | Species, iris, mod.method = "stack") 242 | 243 | 244 | 245 | } 246 | \seealso{ 247 | To plot temporal evolutions: \code{\link[fplot]{plot_lines}}. For boxplot: \code{\link[fplot]{plot_box}}. 248 | To export graphs: \code{\link[fplot]{pdf_fit}}, \code{\link[fplot]{png_fit}}, 249 | \code{\link[fplot]{fit.off}}. 250 | } 251 | \author{ 252 | Laurent Berge 253 | } 254 | -------------------------------------------------------------------------------- /man/plot_lines.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/visualization.R 3 | \name{plot_lines} 4 | \alias{plot_lines} 5 | \title{Display means conditionnally on some other values} 6 | \usage{ 7 | plot_lines( 8 | fml, 9 | data, 10 | time, 11 | moderator, 12 | mod.select, 13 | mod.NA = TRUE, 14 | smoothing_window = 0, 15 | fun, 16 | col = "set1", 17 | lty = 1, 18 | pch = c(19, 17, 15, 8, 5, 4, 3, 1), 19 | legend_options = list(), 20 | pt.cex = 2, 21 | lwd = 2, 22 | dict = NULL, 23 | mod.title = TRUE, 24 | ... 25 | ) 26 | } 27 | \arguments{ 28 | \item{fml}{A formula of the type \code{variable ~ time | moderator}. Note that 29 | the moderator is optional. Can also be a vector representing the elements of 30 | the variable If a formula is provided, then you must add the argument \sQuote{data}. 31 | You can use multiple variables. If so, you cannot use a moderator at the same time.} 32 | 33 | \item{data}{Data frame containing the variables of the formula. Used only if the 34 | argument \sQuote{fml} is a formula.} 35 | 36 | \item{time}{Only if argument \sQuote{fml} is a vector. It should be the vector 37 | of \sQuote{time} identifiers to average over.} 38 | 39 | \item{moderator}{Only if argument \sQuote{fml} is a vector. It should be a vector 40 | of conditional values to average over. This is an optional parameter.} 41 | 42 | \item{mod.select}{Which moderators to select. By default the top 5 moderators 43 | in terms of frequency (or in terms of the value of fun in case of identical 44 | frequencies) are displayed. If provided, it must be a vector of moderator values 45 | whose length cannot be greater than 10. Alternatively, you can put an integer between 1 and 10.} 46 | 47 | \item{mod.NA}{Logical, default is \code{FALSE}. If \code{TRUE}, and if the moderator 48 | contains \code{NA} values, all \code{NA} values from the moderator will be treated 49 | as a regular case: allows to display the distribution for missing values.} 50 | 51 | \item{smoothing_window}{Default is 0. The number of time periods to average over. 52 | Note that if it is provided the new value for each period is the average of 53 | the current period and the \code{smoothing_window} time periods before and after.} 54 | 55 | \item{fun}{Function to apply when aggregating the values on the time variable. 56 | Default is \code{mean}.} 57 | 58 | \item{col}{The colors. Either a vector or a keyword (\dQuote{Set1} or \dQuote{paired}). 59 | By default those are the \dQuote{Set1} colors colorBrewer. This argument is 60 | used only if there is a moderator.} 61 | 62 | \item{lty}{The line types, in the case there are more than one moderator. 63 | By default it is equal to 1 (ie no difference between moderators).} 64 | 65 | \item{pch}{The form types of the points, in the case there are more than one 66 | moderator. By default it is equal to \8code{c(19, 17, 15, 8, 5, 4, 3, 1)}.} 67 | 68 | \item{legend_options}{A list containing additional parameters for the function 69 | \code{\link[graphics]{legend}} -- only concerns the moderator. Note that you can 70 | set the additionnal arguments \code{trunc} and \code{trunc.method} which relates 71 | to the number of characters to show and the truncation method. By default the 72 | algorithm truncates automatically when needed.} 73 | 74 | \item{pt.cex}{Default to 2. The \code{cex} of the points.} 75 | 76 | \item{lwd}{Default to 2. The width of the lines.} 77 | 78 | \item{dict}{A dictionnary to rename the variables names in the axes and legend. 79 | Should be a named vector. By default it s the value of \code{getFplot_dict()}, 80 | which you can set with the function \code{\link[fplot]{setFplot_dict}}.} 81 | 82 | \item{mod.title}{Character scalar. The title of the legend in case there is a 83 | moderator. You can set it to \code{TRUE} (the default) to display the moderator 84 | name. To display no title, set it to \code{NULL} or \code{FALSE}.} 85 | 86 | \item{...}{Other arguments to be passed to the function \code{plot}.} 87 | } 88 | \value{ 89 | This function returns \emph{invisibly} the output data.table containing the processed data 90 | used for plotting. 91 | } 92 | \description{ 93 | The typical use of this function is to represents trends of average along some 94 | categorical variable. 95 | } 96 | \examples{ 97 | 98 | data(airquality) 99 | 100 | plot_lines(Ozone ~ Day, airquality) 101 | 102 | plot_lines(Ozone ~ Day | Month, airquality) 103 | 104 | plot_lines(Ozone ~ Month | cut(Day, 8), airquality) 105 | 106 | 107 | } 108 | \author{ 109 | Laurent Berge 110 | } 111 | -------------------------------------------------------------------------------- /man/png_fit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/miscfuns.R 3 | \name{png_fit} 4 | \alias{png_fit} 5 | \alias{tiff_fit} 6 | \alias{jpeg_fit} 7 | \alias{bmp_fit} 8 | \title{PNG export with guaranteed text size} 9 | \usage{ 10 | png_fit( 11 | file, 12 | pt = 10, 13 | width = 1, 14 | height, 15 | w2h = 1.75, 16 | h2w, 17 | sideways = FALSE, 18 | res = 300, 19 | ... 20 | ) 21 | 22 | tiff_fit( 23 | file, 24 | pt = 10, 25 | width = 1, 26 | height, 27 | w2h = 1.75, 28 | h2w, 29 | sideways = FALSE, 30 | res = 300, 31 | ... 32 | ) 33 | 34 | jpeg_fit( 35 | file, 36 | pt = 10, 37 | width = 1, 38 | height, 39 | w2h = 1.75, 40 | h2w, 41 | sideways = FALSE, 42 | res = 300, 43 | ... 44 | ) 45 | 46 | bmp_fit( 47 | file, 48 | pt = 10, 49 | width = 1, 50 | height, 51 | w2h = 1.75, 52 | h2w, 53 | sideways = FALSE, 54 | res = 300, 55 | ... 56 | ) 57 | } 58 | \arguments{ 59 | \item{file}{The name of the file to which export the figure.} 60 | 61 | \item{pt}{The size of the text, in pt, once the figure is inserted in your final document. 62 | The default is 10. This means that all text appearing in the plot with \code{cex = 1} 63 | will appear with 10pt-sized fonts in your document.} 64 | 65 | \item{width}{The width of the graph, expressed in percentage of the width of 66 | the body-text of the document in which it will be inserted. Default is 1, which means 67 | that the graph will take 100\% of the text width. It can also be equal to a character 68 | of the type \code{"100\%"} or \code{"80\%"}. Alternatively, the following units 69 | are valid. Relative sizes: \code{"pw"} (page width), \code{"tw"} (text width), 70 | \code{"ph"} (page height), \code{"th"} (text height). 71 | Absolute sizes: \code{"in"}, \code{"cm"}, and \code{"px"}.} 72 | 73 | \item{height}{Numeric between 0 and 1 or character scalar. The height of the graph, 74 | expressed in percentage of the height of the body-text of the document in which it 75 | will be inserted. Default is missing, and the height is determined by the other 76 | argument \code{w2h}. This argument should range between 0 and 1. It can also be 77 | equal to a character of the type \code{"100\%"} or \code{"80\%"}. Alternatively, the 78 | following units are valid. Relative sizes: \code{"pw"} (page width), \code{"tw"} 79 | (text width), \code{"ph"} (page height), \code{"th"} (text height). Absolute 80 | sizes: \code{"in"}, \code{"cm"}, and \code{"px"}.} 81 | 82 | \item{w2h}{Numeric scalar. Used to determine the height of the figure based on 83 | the width. By default it is equal to \code{1.75} which means that the graph 84 | will be 1.75 larger than tall. Note that when argument \code{sideways = TRUE}, 85 | the default for the height becomes \verb{90\%}.} 86 | 87 | \item{h2w}{Numeric scalar, default is missing. Used to determine the aspectr ratio of the figure.} 88 | 89 | \item{sideways}{Logical, defaults to \code{FALSE}. If the figure will be placed in 90 | landscape in the final document, then \code{sideways} should be equal to \code{TRUE}. 91 | If TRUE, then the argument \code{width} now refers to the height of the text, and the 92 | argument \code{height} to its width.} 93 | 94 | \item{res}{Numeric, the resolution in ppi. Default is 300.} 95 | 96 | \item{...}{Other arguments to be passed to \code{\link[grDevices:png]{bmp}}, 97 | \code{\link[grDevices]{png}}, \code{\link[grDevices:png]{jpeg}}, or 98 | \code{\link[grDevices:png]{tiff}}. For example: \code{antialias}, \code{bg}, etc.} 99 | } 100 | \value{ 101 | This function does not return anything. It connects the output of the R graphics 102 | engine to a file. 103 | } 104 | \description{ 105 | (\emph{This function is deprecated: Please use the functions \code{\link[=export_graph_start]{export_graph_start()}} 106 | and \code{\link[=export_graph_end]{export_graph_end()}} instead.}) 107 | This is an alternative to \code{\link[grDevices]{png}} and others. It makes it 108 | easy to export figures that should end up in documents. Instead of providing the 109 | height and width of the figure, you provide the fraction of the text-width the figure 110 | should take, and the target font-size at which the plotting text should be rendered. 111 | The size of the plotting text, once the figure is in the final document, is guaranteed. 112 | } 113 | \section{Setting the page size}{ 114 | 115 | 116 | You can set the page size with the function \code{\link[fplot]{setFplot_page}}, 117 | which defines the size of the page and its margins to deduce the size of the body 118 | of the text in which the figures will be inserted. By default the page is considered 119 | to be US-letter with \emph{normal} margins (not too big nor thin). 120 | 121 | It is important to set the page size appropriately to have a final plotting-text size 122 | guaranteed once the figure is inserted in the document. 123 | } 124 | 125 | \examples{ 126 | 127 | 128 | # This function creates figures made to be inserted 129 | # in a Latex document (US-letter with "normal" margins) 130 | # By default, the figures should take 100\% of the 131 | # text width. If so, the size of the text in the figures 132 | # will be exact. 133 | 134 | tmpFile = file.path(tempdir(), "png_examples.png") 135 | 136 | png_fit(tmpFile, pt = 8) 137 | plot(1, 1, type = "n", ann = FALSE) 138 | text(1, 1, "This text will be displayed in 8pt.") 139 | fit.off() 140 | 141 | png_fit(tmpFile, pt = 12) 142 | plot(1, 1, type = "n", ann = FALSE) 143 | text(1, 1, "This text will be displayed in 12pt.") 144 | fit.off() 145 | 146 | png_fit(tmpFile, pt = 12, sideways = TRUE) 147 | plot(1, 1, type = "n", ann = FALSE) 148 | text(1, 1, "This text will be displayed in 12pt if in sideways.") 149 | fit.off() 150 | 151 | # If we reduce the end plot width but keep font size constant 152 | # this will lead to a very big font as compared to the plot 153 | png_fit(tmpFile, pt = 8, width = "50\%") 154 | plot(1, 1, type = "n", ann = FALSE) 155 | text(1, 1, "This text will be displayed in 8pt\nif the graph is 50\% of the text width.") 156 | fit.off() 157 | 158 | } 159 | -------------------------------------------------------------------------------- /man/setFplot_dict.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/miscfuns.R 3 | \docType{data} 4 | \name{setFplot_dict} 5 | \alias{setFplot_dict} 6 | \alias{getFplot_dict} 7 | \title{Sets/gets the dictionary used in \code{fplot}} 8 | \format{ 9 | An object of class \code{function} of length 1. 10 | } 11 | \usage{ 12 | setFplot_dict(dict) 13 | 14 | getFplot_dict 15 | } 16 | \arguments{ 17 | \item{dict}{A named character vector. E.g. to change my variable named "us_md" 18 | and "state" to (resp.) "$ miilion" and "U.S. state", then use 19 | \code{dict = c(us_md="$ million", state = "U.S. state")}.} 20 | } 21 | \value{ 22 | The function \code{setFplot_dict()} does not return anything, it only sets an option after checking 23 | the format of the arguments. 24 | 25 | The function \code{getFplot_dict()} returns a named vector representing the 26 | dictionary set in \code{setFplot_dict()}. 27 | } 28 | \description{ 29 | Sets/gets the default dictionary used to rename the axes/moderator variables 30 | in the functions of the package \code{fplot}. The dictionaries are used to relabel 31 | variables (usually towards a fancier, more explicit formatting) that can be useful 32 | not to explicitly use the arguments xlab/ylab when exporting graphs. By setting 33 | the dictionary with \code{setFplot_dict}, you can avoid providing the argument 34 | \code{dict} in \code{fplot} functions. 35 | } 36 | \details{ 37 | This function stores a named vector in the option "fplot_dict". 38 | The dictionary is automatically accessed by all \code{fplot} functions. 39 | } 40 | \examples{ 41 | 42 | data(airquality) 43 | setFplot_dict(c(Ozone = "Ozone (ppb)")) 44 | plot_distr(Ozone ~ Month, airquality, weight.fun = mean) 45 | 46 | } 47 | \author{ 48 | Laurent Berge 49 | } 50 | \keyword{datasets} 51 | -------------------------------------------------------------------------------- /man/setFplot_distr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/visualization.R 3 | \name{setFplot_distr} 4 | \alias{setFplot_distr} 5 | \alias{getFplot_distr} 6 | \title{Sets the defaults of plot_distr} 7 | \usage{ 8 | setFplot_distr( 9 | sorted, 10 | log, 11 | top, 12 | yaxis.num, 13 | col, 14 | border = "black", 15 | mod.method, 16 | within, 17 | total, 18 | at_5, 19 | labels.tilted, 20 | other, 21 | cumul = FALSE, 22 | centered = TRUE, 23 | weight.fun, 24 | int.categorical, 25 | dict = NULL, 26 | mod.title = TRUE, 27 | labels.angle, 28 | cex.axis, 29 | trunc = 20, 30 | trunc.method = "auto", 31 | reset = FALSE 32 | ) 33 | 34 | getFplot_distr() 35 | } 36 | \arguments{ 37 | \item{sorted}{Logical: should the first elements displayed be the most frequent? 38 | By default this is the case except for numeric values put to log or to integers.} 39 | 40 | \item{log}{Logical, only used when the data is numeric. If \code{TRUE}, then 41 | the data is put to logarithm beforehand. By default numeric values are put to 42 | log if the log variation exceeds 3.} 43 | 44 | \item{top}{What to display on the top of the bars. Can be equal to "frac" (for 45 | shares), "nb" or "none". The default depends on the type of the plot. To disable 46 | it you can also set it to \code{FALSE} or the empty string.} 47 | 48 | \item{yaxis.num}{Whether the y-axis should display regular numbers instead of 49 | frequencies in percentage points. By default it shows numbers only when the data 50 | is weighted with a different function than the sum. For conditionnal distributions, 51 | a numeric y-axis can be displayed only when \code{mod.method = "sideTotal"}, 52 | \code{mod.method = "splitTotal"} or \code{mod.method = "stack"}, since for the 53 | within distributions it does not make sense (because the data is rescaled for each moderator).} 54 | 55 | \item{col}{A vector of colors, default is close to paired. You can also use \dQuote{set1} 56 | or \dQuote{paired}.} 57 | 58 | \item{border}{Outer color of the bars. Defaults is \code{"black"}. Use \code{NA} 59 | to remove the borders.} 60 | 61 | \item{mod.method}{A character scalar: either i) \dQuote{split}, the default for 62 | categorical data, ii) \dQuote{side}, the default for data in logarithmic form 63 | or numeric data, or iii) \dQuote{stack}. This is only used when there is more 64 | ù than one moderator. If \code{"split"}: there is one separate histogram for each 65 | moderator case. If \code{"side"}: moderators are represented side by side for 66 | each value of the variable. If \code{"stack"}: the bars of the moderators are 67 | stacked onto each other, the bar heights representing the distribution in the 68 | total population. You can use the other arguments \code{within} and \code{total} 69 | to say whether the distributions should be within each moderator or over the 70 | total distribution.} 71 | 72 | \item{within}{Logical, default is missing. Whether the distributions should be 73 | scaled to reflect the distribution within each moderator value. By default it 74 | is \code{TRUE} if \code{mod.method} is different from \code{"stack"}.} 75 | 76 | \item{total}{Logical, default is missing. Whether the distributions should be 77 | scaled to reflect the total distribution (and not the distribution within each 78 | moderator value). By default it is \code{TRUE} only if \code{mod.method="stack"}.} 79 | 80 | \item{at_5}{Equal to \code{FALSE}, \code{"roman"} or \code{"line"}. When plotting 81 | categorical variables, adds a small Roman number under every 5 bars 82 | (\code{at_5 = "roman"}), or draws a thick axis line every 5 bars (\code{at_5 = "line"}). 83 | Helps to get the rank of the bars. The default depends on the type of data -- 84 | Not implemented when there is a moderator.} 85 | 86 | \item{labels.tilted}{Whether there should be tilted labels. Default is \code{FALSE} 87 | except when the data is split by moderators (see \code{mod.method}).} 88 | 89 | \item{other}{Logical. Should there be a last column counting for the observations 90 | not displayed? Default is \code{TRUE} except when the data is split.} 91 | 92 | \item{cumul}{Logical, default is \code{FALSE}. If \code{TRUE}, then the cumulative 93 | distribution is plotted.} 94 | 95 | \item{centered}{Logical, default is \code{TRUE}. For numeric data only and when 96 | \code{sorted=FALSE}, whether the histogram should be centered on the mode.} 97 | 98 | \item{weight.fun}{A function, by default it is \code{sum}. Aggregate function 99 | to be applied to the weight with respect to variable and the moderator. See examples.} 100 | 101 | \item{int.categorical}{Logical. Whether integers should be treated as categorical 102 | variables. By default they are treated as categorical only when their range is 103 | small (i.e. smaller than 1000).} 104 | 105 | \item{dict}{A dictionnary to rename the variables names in the axes and legend. 106 | Should be a named vector. By default it s the value of \code{getFplot_dict()}, 107 | which you can set with the function \code{\link[fplot]{setFplot_dict}}.} 108 | 109 | \item{mod.title}{Character scalar. The title of the legend in case there is a 110 | moderator. You can set it to \code{TRUE} (the default) to display the moderator 111 | name. To display no title, set it to \code{NULL} or \code{FALSE}.} 112 | 113 | \item{labels.angle}{Only if the labels of the x-axis are tilted. The angle of the tilt.} 114 | 115 | \item{cex.axis}{Cex value to be passed to biased labels. By defaults, it finds 116 | automatically the right value.} 117 | 118 | \item{trunc}{If the main variable is a character, its values are truncaded to 119 | \code{trunc} characters. Default is 20. You can set the truncation method with 120 | the argument \code{trunc.method}.} 121 | 122 | \item{trunc.method}{If the elements of the x-axis need to be truncated, this 123 | is the truncation method. It can be "auto", "right" or "mid".} 124 | 125 | \item{reset}{Logical scalar, default is \code{FALSE}. Whether the defaults should be reset.} 126 | } 127 | \value{ 128 | The function \code{setFplot_distr()} does not return anything, it only sets the default 129 | parameters for the function \code{\link[=plot_distr]{plot_distr()}}. 130 | 131 | The function \code{getFplot_distr()} returns a named list containing the arguments 132 | that have been set with the function \code{setFplot_distr()}. 133 | } 134 | \description{ 135 | The default values of most arguments of \code{\link[fplot]{plot_distr}} can be 136 | set with \code{setFplot_distr}. 137 | } 138 | \examples{ 139 | 140 | # Changing the default color set for plot_distr only 141 | my_col = c("#36688D", "#F3CD05", "#F49F05", "#F18904", "#BDA589") 142 | 143 | setFplot_distr(col = my_col, mod.method = "split", border = NA) 144 | 145 | plot_distr(~ Petal.Length | Species, iris) 146 | 147 | # Back to normal 148 | setFplot_distr(reset = TRUE) 149 | 150 | plot_distr(~ Petal.Length | Species, iris) 151 | 152 | 153 | 154 | } 155 | \seealso{ 156 | \code{\link[fplot]{plot_distr}}, \code{\link[fplot]{pdf_fit}}, \code{\link[fplot]{fit.off}}. 157 | } 158 | -------------------------------------------------------------------------------- /man/setFplot_page.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/miscfuns.R 3 | \name{setFplot_page} 4 | \alias{setFplot_page} 5 | \alias{getFplot_page} 6 | \title{Sets the target page size for figure exporting} 7 | \usage{ 8 | setFplot_page( 9 | page = "us", 10 | margins = "normal", 11 | units = "tw", 12 | pt = 10, 13 | w2h = 1.75, 14 | reset = FALSE 15 | ) 16 | 17 | getFplot_page() 18 | } 19 | \arguments{ 20 | \item{page}{What is the page size of the document? Can be equal to "us" (for 21 | US letter, the default) or "a4". Can also be a numeric vector of length 2 giving 22 | the width and the height of the page in \strong{inches}. Or can be a character string 23 | of the type: \code{"8.5in,11in"} where the width and height are separated with 24 | a comma, note that only centimeters (cm), inches (in) and pixels (px) are accepted 25 | as units--further: you can use the unit only once.} 26 | 27 | \item{margins}{The bottom/left/top/right margins of the page. This is used to 28 | obtain the dimension of the body of the text. Can be equal to "normal" (default, 29 | which corresponds to 2cm/2.5cm/2cm/2.5cm), or to "thin" (1.5/1/1/1cm). Can be 30 | a numeric vector of length 1: then all margins are the same given size in \strong{inches}. 31 | 32 | Can also be a numeric vector of length 2 or 4: 2 means first bottom/top margins, 33 | then left/right margins; 4 is bottom/left/top/right margins, in inches. Last, 34 | it can be a character vector of the type \code{"2,2.5,2,2.5cm"} with the margins 35 | separated by a comma or a slash, and at least one unit appearing: either \code{cm}, 36 | \code{in} or \code{px}.} 37 | 38 | \item{units}{The default units when using the functions \code{\link[fplot]{pdf_fit}}, 39 | \code{\link[fplot]{png_fit}}, etc. Defaults to \code{"tw"} (text width) which 40 | is a fraction of the size of the text. Alternatives can be \code{"pw"} (page 41 | width), and \code{"in"}, \code{"cm"}, \code{"px"}.} 42 | 43 | \item{pt}{The size of the text, in pt, once the figure is inserted in your final document. 44 | The default is 10. This means that all text appearing in the plot with \code{cex = 1} 45 | will appear with 10pt-sized fonts in your document.} 46 | 47 | \item{w2h}{Numeric scalar. Used to determine the height of the figure based on 48 | the width. By default it is equal to \code{1.75} which means that the graph 49 | will be 1.75 larger than tall. Note that when argument \code{sideways = TRUE}, 50 | the default for the height becomes \verb{90\%}.} 51 | 52 | \item{reset}{Logical, default is \code{FALSE}. Whether arguments should be reset 53 | to default before applying modifications.} 54 | } 55 | \value{ 56 | The function \code{setFplot_page()} does not return anything. It sets an 57 | R option containing the page parameters. 58 | 59 | The function \code{getFplot_page()} returns the named list of page parameters which has been set 60 | in \code{setFplot_page()}. 61 | } 62 | \description{ 63 | Tha package \code{fplot} offers some functions (e.g. \code{\link[fplot]{pdf_fit}} 64 | or \code{\link[fplot]{png_fit}}) to export figures, with a guarantee to obtain 65 | the desired point size for the plotting text. The function \code{setFplot_page} 66 | sets the target page size (once and for all). This is important for the accuracy 67 | of the export, although the default values should be working well most of the time. 68 | } 69 | \details{ 70 | This function sets the option "fplot_export_opts" after parsing the arguments. 71 | This option is then automatically accessed by the functions used to export graphs 72 | \code{\link[=export_graph_start]{export_graph_start()}}. 73 | } 74 | \examples{ 75 | 76 | # 77 | # How to set the page size 78 | # 79 | 80 | # All examples below provide the same page size 81 | setFplot_page(page = "us") 82 | setFplot_page(page = "8.5in, 11in") 83 | setFplot_page(page = "8.5/11in") 84 | setFplot_page(page = c(8.5, 11)) 85 | 86 | # All examples below provide the same margins 87 | setFplot_page(margins = "normal") 88 | setFplot_page(margins = "2cm, 2.5cm, 2cm, 2.5cm") 89 | setFplot_page(margins = "2/2.5/2/2.5cm") 90 | setFplot_page(margins = c(2, 2.5) / 2.54) # cm to in 91 | setFplot_page(margins = c(2, 2.5, 2, 2.5) / 2.54) 92 | 93 | } 94 | \seealso{ 95 | Exporting functions: \code{\link[fplot]{pdf_fit}}, \code{\link[fplot]{png_fit}}. 96 | The function closing the connection and showing the obtained graph in the viewer: 97 | \code{\link[fplot]{fit.off}}. 98 | } 99 | -------------------------------------------------------------------------------- /man/us_pub_econ.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/miscfuns.R 3 | \docType{data} 4 | \name{us_pub_econ} 5 | \alias{us_pub_econ} 6 | \title{Publication data sample} 7 | \format{ 8 | \code{us_pub_econ} is a data table with 30,756 observations and 6 variables. 9 | 10 | \itemize{ 11 | \item{paper_id: Numeric identifier of the publication.} 12 | \item{year: Year of publication.} 13 | \item{institution: Institution of the authors of the publication.} 14 | \item{journal: Journal/conference name.} 15 | \item{jnl_top_25p: 0/1 variable of whether the journal belongs to the top 25\% in terms of average cites.} 16 | \item{jnl_top_5p: 0/1 variable of whether the journal belongs to the top 5\% in terms of average cites.} 17 | 18 | } 19 | } 20 | \source{ 21 | The source is Microsoft Academic Graph (see reference). 22 | } 23 | \usage{ 24 | data(us_pub_econ) 25 | } 26 | \description{ 27 | This data reports the publications of U.S. institutions in the field of economics between 1985 and 1990. 28 | } 29 | \references{ 30 | Arnab Sinha, Zhihong Shen, Yang Song, Hao Ma, Darrin Eide, Bo-June (Paul) Hsu, and Kuansan Wang. 2015. An Overview of Microsoft Academic Service (MAS) and Applications. In Proceedings of the 24th International Conference on World Wide Web (WWW '15 Companion). ACM, New York, NY, USA, 243-246. 31 | } 32 | \keyword{datasets} 33 | -------------------------------------------------------------------------------- /src/Makevars: -------------------------------------------------------------------------------- 1 | 2 | PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS) 3 | PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) 4 | 5 | -------------------------------------------------------------------------------- /src/Makevars.win: -------------------------------------------------------------------------------- 1 | 2 | PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS) 3 | PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) 4 | -------------------------------------------------------------------------------- /src/RcppExports.cpp: -------------------------------------------------------------------------------- 1 | // Generated by using Rcpp::compileAttributes() -> do not edit by hand 2 | // Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 3 | 4 | #include 5 | 6 | using namespace Rcpp; 7 | 8 | #ifdef RCPP_USE_GLOBAL_ROSTREAM 9 | Rcpp::Rostream& Rcpp::Rcout = Rcpp::Rcpp_cout_get(); 10 | Rcpp::Rostream& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get(); 11 | #endif 12 | 13 | // cpp_unclassFactor 14 | IntegerVector cpp_unclassFactor(NumericVector x); 15 | RcppExport SEXP _fplot_cpp_unclassFactor(SEXP xSEXP) { 16 | BEGIN_RCPP 17 | Rcpp::RObject rcpp_result_gen; 18 | Rcpp::RNGScope rcpp_rngScope_gen; 19 | Rcpp::traits::input_parameter< NumericVector >::type x(xSEXP); 20 | rcpp_result_gen = Rcpp::wrap(cpp_unclassFactor(x)); 21 | return rcpp_result_gen; 22 | END_RCPP 23 | } 24 | // cpp_unik 25 | IntegerVector cpp_unik(NumericVector x_sorted, int k_max); 26 | RcppExport SEXP _fplot_cpp_unik(SEXP x_sortedSEXP, SEXP k_maxSEXP) { 27 | BEGIN_RCPP 28 | Rcpp::RObject rcpp_result_gen; 29 | Rcpp::RNGScope rcpp_rngScope_gen; 30 | Rcpp::traits::input_parameter< NumericVector >::type x_sorted(x_sortedSEXP); 31 | Rcpp::traits::input_parameter< int >::type k_max(k_maxSEXP); 32 | rcpp_result_gen = Rcpp::wrap(cpp_unik(x_sorted, k_max)); 33 | return rcpp_result_gen; 34 | END_RCPP 35 | } 36 | // cpp_string_shorten 37 | std::string cpp_string_shorten(std::string x, int max_size); 38 | RcppExport SEXP _fplot_cpp_string_shorten(SEXP xSEXP, SEXP max_sizeSEXP) { 39 | BEGIN_RCPP 40 | Rcpp::RObject rcpp_result_gen; 41 | Rcpp::RNGScope rcpp_rngScope_gen; 42 | Rcpp::traits::input_parameter< std::string >::type x(xSEXP); 43 | Rcpp::traits::input_parameter< int >::type max_size(max_sizeSEXP); 44 | rcpp_result_gen = Rcpp::wrap(cpp_string_shorten(x, max_size)); 45 | return rcpp_result_gen; 46 | END_RCPP 47 | } 48 | 49 | static const R_CallMethodDef CallEntries[] = { 50 | {"_fplot_cpp_unclassFactor", (DL_FUNC) &_fplot_cpp_unclassFactor, 1}, 51 | {"_fplot_cpp_unik", (DL_FUNC) &_fplot_cpp_unik, 2}, 52 | {"_fplot_cpp_string_shorten", (DL_FUNC) &_fplot_cpp_string_shorten, 2}, 53 | {NULL, NULL, 0} 54 | }; 55 | 56 | RcppExport void R_init_fplot(DllInfo *dll) { 57 | R_registerRoutines(dll, NULL, CallEntries, NULL, NULL); 58 | R_useDynamicSymbols(dll, FALSE); 59 | } 60 | -------------------------------------------------------------------------------- /src/misc_funs.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace Rcpp; 4 | 5 | 6 | // [[Rcpp::export]] 7 | IntegerVector cpp_unclassFactor(NumericVector x){ 8 | // x: a sorted integer vector 9 | 10 | int N = x.size(); 11 | 12 | IntegerVector res(N); 13 | int k=1; 14 | res[0] = 1; 15 | 16 | for(int i=1 ; i 7 | %\VignetteIndexEntry{Exporting graphs} 8 | %\VignetteEngine{knitr::rmarkdown} 9 | %\VignetteEncoding{UTF-8} 10 | --- 11 | 12 | ```{r setup, include=FALSE} 13 | knitr::opts_chunk$set(echo = TRUE, eval = FALSE) 14 | ``` 15 | 16 | ## Exporting graphs with `fplot` 17 | 18 | Exporting a graph is often a chore, especially if you want to have the best looking 19 | graphs in your publications. One common problem is that it is usually difficult 20 | to predict how the text contained in the graph will look once in its final location 21 | (i.e. in your document). You may end up with text looking either too big or too small. 22 | 23 | `fplot` provides a set of tools to simplify graph exportation. This is achieved 24 | thanks to a different philosophy from existing export functions: instead of giving 25 | the target size of the figure (width/height), just give the desired point size of 26 | the text. The graph will be created such that once it's in your final document, 27 | the size of the text in the graph will be equal to the desired point size. 28 | 29 | In essence, it's a reparametrization of existing export functions. Below a simple 30 | example is detailed. 31 | 32 | ## Example 33 | 34 | You can export any kind of graph with the functions `export_graph_start()` and 35 | `export_graph_end()`. 36 | 37 | But first things first, you need to provide the size the image will take in your 38 | final document. 39 | 40 | By default, the target location of the graph is a *US letter* page with "normal" 41 | margins (i.e. 2.5cm left and right, 2cm top and bottom). You can change it globally 42 | with the function `setFplot_page`. Let's change it to A4 and one inch margins on all sides: 43 | 44 | ```{r} 45 | library(fplot) 46 | setFplot_page(page = "a4", margins = 1) 47 | ``` 48 | 49 | Now let's go for the first export: 50 | 51 | ```{r, eval = FALSE} 52 | export_graph_start("first_export.pdf") 53 | plot(1, 1, type = "n", ann = FALSE) 54 | text(1, 1, "This text will be displayed in 10pt.") 55 | export_graph_end() 56 | ``` 57 | 58 | You can notice that in the end of the export, `export_graph_end` is used in lieu of 59 | `dev.off` (which must be familier to the ones used to export with base R tools). 60 | This function does the same thing as `dev.off` but also displays the exported graph 61 | in the Viewer pane of RStudio or VSCode (provided you use it). This way you can directly see 62 | how the exported graph looks. 63 | 64 | What about the geometry of the graph? By default the width of the plot is 100% of 65 | the text width. You can change it with the `width` argument: e.g. using relative 66 | widths `width = 0.5` (50% of the text width), `width = "50%"` (idem), or absolute 67 | widths `width = "10cm"`, `width = "5in"`, etc. 68 | 69 | The width to height ratio can be modified with the `w2h` argument (or you can use 70 | `h2w` for the inverse ratio). The default is `w2h = 1.75` (close to the Golden ratio). 71 | 72 | Finally the default point size is `pt = 10`. If embedded in an A4 page with 1 inch 73 | margins on both sides, the text of the previously exported graph would be in 10pt: 74 | 75 | ![Figure 1: Text in 10pt.](images/export_example_10pt.png) 76 | 77 | If you increase the pt size that's what you would get: 78 | 79 | ```{r, eval = FALSE} 80 | export_graph_start("second_export.pdf", pt = 12) 81 | plot(1, 1, type = "n", ann = FALSE) 82 | text(1, 1, "This text will be displayed in 12pt.") 83 | export_graph_end() 84 | ``` 85 | 86 | 87 | ![Figure 2: Text in 12pt.](images/export_example_12pt.png) 88 | 89 | As we can see, with a larger font any text is larger, and since there is 90 | text in the margins, the plotting region becomes smaller. 91 | 92 | With this way of exporting, you need to worry only on two things: 93 | 94 | 1. the final text size of the graph (and you should be worried about it anyway) 95 | that you can provide explicitly, 96 | 2. the width to height ratio of the graph. 97 | 98 | 99 | To create the same graph as before but which would take the total height of the 100 | page, just use the argument `height = 1` (`height = 100%` or `height = 1th`, 101 | *th* meaning **t**ext **h**eight would also work): 102 | 103 | ```{r, eval = FALSE} 104 | export_graph_start("third_export.pdf", pt = 12, height = 1) 105 | plot(1, 1, type = "n", ann = FALSE) 106 | text(1, 1, "This text will be displayed in 12pt.") 107 | export_graph_end() 108 | ``` 109 | 110 | ![Figure 3: Text in 12pt, total page height.](images/export_example_12pt_tall.png) 111 | 112 | Finally if you use `sideways = TRUE`, the settings become `width = 1th` (100% text height) 113 | and `height = 0.9tw` (90% text width), i.e. the graph would take the full page 114 | except a 10% space left for the graph legend. 115 | 116 | ```{r, eval = FALSE} 117 | # You can also set the point size globally 118 | setFplot_page(pt = 12) 119 | export_graph_start("fourth_export.pdf", sideways = TRUE) 120 | plot(1, 1, type = "n", ann = FALSE) 121 | text(1, 1, "This text will be displayed in 12pt.") 122 | export_graph_end() 123 | ``` 124 | 125 | ![Figure 4: Text in 12pt, sideways.](images/export_example_12pt_sideways.png) 126 | 127 | 128 | # Changelog 129 | 130 | - version 1.1.0: `export_graph_start` and `export_graph_end` replace the family of 131 | functions `*_fit` and `fit.off()`. 132 | 133 | -------------------------------------------------------------------------------- /vignettes/images/conditional_iris_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/vignettes/images/conditional_iris_1.png -------------------------------------------------------------------------------- /vignettes/images/conditional_iris_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/vignettes/images/conditional_iris_2.png -------------------------------------------------------------------------------- /vignettes/images/conditional_iris_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/vignettes/images/conditional_iris_3.png -------------------------------------------------------------------------------- /vignettes/images/conditional_pub_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/vignettes/images/conditional_pub_1.png -------------------------------------------------------------------------------- /vignettes/images/conditional_pub_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/vignettes/images/conditional_pub_2.png -------------------------------------------------------------------------------- /vignettes/images/conditional_pub_3_bis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/vignettes/images/conditional_pub_3_bis.png -------------------------------------------------------------------------------- /vignettes/images/conditional_trade_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/vignettes/images/conditional_trade_1.png -------------------------------------------------------------------------------- /vignettes/images/conditional_trade_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/vignettes/images/conditional_trade_2.png -------------------------------------------------------------------------------- /vignettes/images/cumul_iris.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/vignettes/images/cumul_iris.png -------------------------------------------------------------------------------- /vignettes/images/cumul_pub.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/vignettes/images/cumul_pub.png -------------------------------------------------------------------------------- /vignettes/images/cumul_trade.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/vignettes/images/cumul_trade.png -------------------------------------------------------------------------------- /vignettes/images/export_example_10pt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/vignettes/images/export_example_10pt.png -------------------------------------------------------------------------------- /vignettes/images/export_example_12pt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/vignettes/images/export_example_12pt.png -------------------------------------------------------------------------------- /vignettes/images/export_example_12pt_sideways.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/vignettes/images/export_example_12pt_sideways.png -------------------------------------------------------------------------------- /vignettes/images/export_example_12pt_tall.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/vignettes/images/export_example_12pt_tall.png -------------------------------------------------------------------------------- /vignettes/images/regular_iris.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/vignettes/images/regular_iris.png -------------------------------------------------------------------------------- /vignettes/images/regular_pub.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/vignettes/images/regular_pub.png -------------------------------------------------------------------------------- /vignettes/images/regular_trade.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/vignettes/images/regular_trade.png -------------------------------------------------------------------------------- /vignettes/images/weighted_conditional_trade_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/vignettes/images/weighted_conditional_trade_1.png -------------------------------------------------------------------------------- /vignettes/images/weighted_conditional_trade_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/vignettes/images/weighted_conditional_trade_2.png -------------------------------------------------------------------------------- /vignettes/images/weighted_pub_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/vignettes/images/weighted_pub_1.png -------------------------------------------------------------------------------- /vignettes/images/weighted_pub_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/vignettes/images/weighted_pub_2.png -------------------------------------------------------------------------------- /vignettes/images/weighted_stacked_pub.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/vignettes/images/weighted_stacked_pub.png -------------------------------------------------------------------------------- /vignettes/images/weighted_stacked_trade.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/vignettes/images/weighted_stacked_trade.png -------------------------------------------------------------------------------- /vignettes/images/weighted_trade_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/vignettes/images/weighted_trade_1.png -------------------------------------------------------------------------------- /vignettes/images/weighted_trade_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrberge/fplot/2f585a358a7711d01a4e2720958a0dc1de24145b/vignettes/images/weighted_trade_2.png --------------------------------------------------------------------------------