You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Documentation feature request: Include examples in autoplot's documentation. #4777
autoplot looks like great fun to play around with, but I see two major issues:
Little help for it seems to be easily available online
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.
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.
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.1mtx<-matrix(1:12, 3, 4)
# Matrix as tidy datafortify.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 layerautolayer.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 plotautoplot.matrix<-function(object, ...) {
ggplot(...) +
autolayer(object) +# Adding a scale for the matrix
scale_fill_viridis_c()
}
autoplot(mtx)
Activity
yutannihilation commentedon Apr 23, 2022
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.
ggplot2/NAMESPACE
Line 17 in 21df8dc
92amartins commentedon Sep 25, 2023
Maybe we could write a vignette describing the main use cases.
Happy to send a PR if that's the case.
teunbrand commentedon Sep 25, 2023
I think a vignette might be overdoing it a bit, but it probably could get a separate docpage together with
autolayer()and maybefortify(). In the example section, you could simply implement dummy methods for a matrix or something, see below.Created on 2023-09-25 with reprex v2.0.2