Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ReeceGoding opened this issue Mar 27, 2022 · 3 comments · Fixed by #5745
Closed

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

ReeceGoding opened this issue Mar 27, 2022 · 3 comments · Fixed by #5745
Labels
Milestone

Comments

@ReeceGoding
Copy link

ReeceGoding commented Mar 27, 2022

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.

@yutannihilation
Copy link
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)

@92amartins
Copy link
Contributor

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

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

@teunbrand
Copy link
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants