Skip to content

Commit

Permalink
updates to the documentation, add nudges for plot height and width
Browse files Browse the repository at this point in the history
  • Loading branch information
rdboyes committed Oct 30, 2021
1 parent 4b6942b commit a0c1d6c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Description: This package uses patchwork to overlay forest plots created in
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.1.1
RoxygenNote: 7.1.2
Imports:
dplyr,
ggplot2,
Expand All @@ -37,3 +37,4 @@ Suggests:
rmarkdown,
readxl
VignetteBuilder: knitr
Roxygen: list(markdown = TRUE)
10 changes: 7 additions & 3 deletions R/forester.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Create a forest plot column in a table
#'
#' Creates an png image with the forest plot column inserted in the supplied data frame.
#' Creates a forest plot overlaid on a table.
#'
#' @param left_side_data Data frame (required). The information to be displayed to the left of the forest plot.
#' @param estimate Vector. The point estimates to be displayed in the forest plot.
Expand All @@ -23,6 +23,8 @@
#' @param xbreaks Vector. X axis breaks to label. Specify limits in xlim if using this option.
#' @param nudge_x Numeric. Nudge the alignment horizontally. Default 1. Higher values make the entire plot wider and consequently space out the elements of the figure.
#' @param nudge_y Numeric. Allows small changes to the vertical alignment of the forest plot points. 1 unit is approximately the height of 1 row.
#' @param nudge_height Numeric. Adjust the overall height of the plot output. Default is 0.
#' @param nudge_width Numeric. Adjust the overall width of the plot output. Default is 0.
#' @param arrows Logical. Should there be arrows displayed below the ggplot? Default FALSE. Specify xlim if using arrows.
#' @param arrow_labels String Vector, length 2. Labels for the arrows. Set arrows to TRUE or this will have no effect.
#' @param add_plot A ggplot object to add to the right side of the table. To align correctly with rows, 1 unit is the height of a row and y = 0 for the center of the bottom row.
Expand Down Expand Up @@ -62,6 +64,8 @@ forester <- function(left_side_data,
xbreaks = NULL,
nudge_y = 0,
nudge_x = 1,
nudge_height = 0,
nudge_width = 0,
arrows = FALSE,
arrow_labels = c("Lower", "Higher"),
add_plot = NULL,
Expand Down Expand Up @@ -532,8 +536,8 @@ forester <- function(left_side_data,
if(!(render_as == "rmarkdown")){
ggplot2::ggsave(
dpi = dpi,
height = png_height,
width = png_width,
height = png_height + nudge_height,
width = png_width + nudge_width,
units = "in",
filename = file_path,
device = render_as
Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ forester(left_side_data = table[,1],

## Display Options

By default, forester will both display the plot in the RStudio viewer (`display = TRUE`) and save a high quality version to the current directory (`file_path = here::here("forester_plot.png")`) at a resolution controllable by `dpi`. When making a rmarkdown document (such as this one), these options should be overwritten as required. You can display the images created by forester using standard RMarkdown syntax (i.e. `![](path)`).
Using the default options will result in a png image being written to your temporary folder and opened with your default program for viewing images. If you don't want to open the file, specify `display = FALSE`. `ggplot2::ggsave` is used to save the file, so any format supported there will work in theory (though not necessarily in practice). Use the `render_as` option to change the output file format - for example, `render_as = "pdf"` will render the plot in pdf form. If you want to display the plot inline in an rmarkdown document, use `render_as = "rmarkdown` (this feature is still experimental). You can alternatively generate the plots as images and then use normal markdown syntax to include them in your document (i.e. `![]()`). Be sure to change the `file_path` option to save the plot somewhere permanent if you are using this option or would otherwise like your plots to be saved.

## Font Families

Expand Down
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,20 @@ forester(left_side_data = table[,1],

## Display Options

By default, forester will both display the plot in the RStudio viewer
(`display = TRUE`) and save a high quality version to the current
directory (`file_path = here::here("forester_plot.png")`) at a
resolution controllable by `dpi`. When making a rmarkdown document (such
as this one), these options should be overwritten as required. You can
display the images created by forester using standard RMarkdown syntax
(i.e. `![](path)`).
Using the default options will result in a png image being written to
your temporary folder and opened with your default program for viewing
images. If you don’t want to open the file, specify `display = FALSE`.
`ggplot2::ggsave` is used to save the file, so any format supported
there will work in theory (though not necessarily in practice). Use the
`render_as` option to change the output file format - for example,
`render_as = "pdf"` will render the plot in pdf form. If you want to
display the plot inline in an rmarkdown document, use
`render_as = "rmarkdown` (this feature is still experimental). You can
alternatively generate the plots as images and then use normal markdown
syntax to include them in your document (i.e. `![]()`). Be sure to
change the `file_path` option to save the plot somewhere permanent if
you are using this option or would otherwise like your plots to be
saved.

## Font Families

Expand Down
2 changes: 0 additions & 2 deletions man/forester.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a0c1d6c

Please sign in to comment.