Skip to content

Commit

Permalink
Complement documentation for atom plots (#185)
Browse files Browse the repository at this point in the history
* Complement documentation for atom plots

* Don't run vertical/horizontal lines, issue with ggplot current release

* Fix mapping of vertical line from addLine

* Don't run vertical/horizontal line from doc examples
  • Loading branch information
pchelle committed Oct 21, 2021
1 parent 82aa7fd commit 0df22e1
Show file tree
Hide file tree
Showing 4 changed files with 293 additions and 145 deletions.
7 changes: 4 additions & 3 deletions R/atom-plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ addScatter <- function(data = NULL,
data <- data.frame(data, check.names = FALSE)
}

dataMapping <- dataMapping %||% XYGDataMapping$new(x = x, y = y, data = data)
dataMapping <- dataMapping %||% XYGDataMapping$new(x = "x", y = "y", data = data)
plotConfiguration <- plotConfiguration %||% PlotConfiguration$new(data = data, metaData = metaData, dataMapping = dataMapping)
# Update plotConfiguration if user defined aesthetics
eval(parseVariableToObject("plotConfiguration$points", c("color", "shape", "linetype", "size"), keepIfNull = TRUE))
Expand Down Expand Up @@ -198,6 +198,7 @@ addScatter <- function(data = NULL,
#' aesthetic properties defined in `plotConfiguration` will apply across all layers.
#' @return A `ggplot` graphical object
#' @examples
#' \dontrun{
#' # Add vertical line at x = 2
#' addLine(x = 2)
#'
Expand All @@ -211,7 +212,7 @@ addScatter <- function(data = NULL,
#'
#' # Add horizontal line at y = 5 to a previous plot
#' p <- addLine(y = 5, plotObject = p)
#'
#'}
#' # Add a custom line
#' time <- seq(0, 30, 0.01)
#' customLineData <- data.frame(x = time, y = cos(time))
Expand Down Expand Up @@ -254,7 +255,7 @@ addLine <- function(data = NULL,
data <- data.frame(data, check.names = FALSE)
}

dataMapping <- dataMapping %||% XYGDataMapping$new(x = x, y = y, data = data)
dataMapping <- dataMapping %||% XYGDataMapping$new(x = "x", y = "y", data = data)
plotConfiguration <- plotConfiguration %||% PlotConfiguration$new(data = data, metaData = metaData, dataMapping = dataMapping)
# Update plotConfiguration if user defined aesthetics
eval(parseVariableToObject("plotConfiguration$lines", c("color", "shape", "linetype", "size"), keepIfNull = TRUE))
Expand Down
4 changes: 2 additions & 2 deletions R/utilities-mapping.R
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ smartMapping <- function(data) {

# Names of data.frame variables
variableNames <- names(data)
# If one column, set as y
if (ncol(data) == 1) {
# If one column, set as y unless name is "x"
if (ncol(data) == 1 & !(variableNames[1] %in% "x")) {
mapping$y <- variableNames[1]
}
# If 2 columns, set as x, y
Expand Down
3 changes: 2 additions & 1 deletion man/addLine.Rd

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

Loading

0 comments on commit 0df22e1

Please sign in to comment.