Skip to content

Documentation feature request: Include examples in autoplot's documentation. #4777

Closed

Description

@ReeceGoding

autoplot looks like great fun to play around with, but I see two major issues:

  1. Little help for it seems to be easily available online
  2. The documentation contains no examples whatsoever

I believe that adding some examples to its documentation would greatly improve it. At present, the user is largely left to guess what sort of inputs it will accept.

Activity

  1. yutannihilation commented on Apr 23, 2022

    @yutannihilation
    Member

    I think this is a good idea, but the problem is that ggplot2 doesn't include any of the actual method implementation. So, I'm afraid this is difficult to do within ggplot2's document.

    S3method(autoplot,default)

  2. 92amartins commented on Sep 25, 2023

    @92amartins
    Contributor

    Maybe we could write a vignette describing the main use cases.

    Happy to send a PR if that's the case.

  3. teunbrand commented on Sep 25, 2023

    @teunbrand
    Collaborator

    I think a vignette might be overdoing it a bit, but it probably could get a separate docpage together with autolayer() and maybe fortify(). In the example section, you could simply implement dummy methods for a matrix or something, see below.

    library(ggplot2)
    #> Warning: package 'ggplot2' was built under R version 4.3.1
    
    mtx <- matrix(1:12, 3, 4)
    
    # Matrix as tidy data
    fortify.matrix <- function(model, ...) {
      dims <- dim(model)
      data.frame(
        row   = as.vector(.row(dims)),
        col   = as.vector(.col(dims)),
        value = as.vector(model)
      )
    }
    
    ggplot(mtx, aes(col, row, fill = value)) +
      geom_raster()

    # Converting matrices to a raster layer
    autolayer.matrix <- function(object, ...) {
      # We can use `data = object` here because we've defined a `fortify()`
      # method above
      geom_raster(aes(x = col, y = row, fill = value), data = object, ...)
    }
    
    ggplot() + autolayer(mtx)

    # Converting matrices to a plot
    autoplot.matrix <- function(object, ...) {
      ggplot(...) +
        autolayer(object) +
        # Adding a scale for the matrix
        scale_fill_viridis_c()
    }
    
    autoplot(mtx)

    Created on 2023-09-25 with reprex v2.0.2

  4. added this to the ggplot2 3.5.1 milestone on Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions