-
Couldn't load subscription status.
- Fork 2.1k
Description
(Originally commented at #3802 (comment))
In my understanding, there are 2 purposes of fortify().
- User-facing utility to convert an object to data.frame, which otherwise the users don't know how to.
- API for developers that let the custom objects handled nicely in the internal of ggplot2 by tweaking the object at the very first stage.
For purpose 1, ggplot2 now provides 2 types of methods, both of which are becoming less important:
- Convert model objects, which is superseded broom package. In addition, ggfortify covers much wider range of objects.
- Convert geospatial objects (of sp and maps), which is being superseded by sf package and
geom_sf().
So, we can and should deprecate (or at least discourage) this type of usages.
On the other hand, for purpose 2, I think fortify() still plays a somehow important role. For example, fortify.tbl() ensures tbl is collect()ed.
Lines 19 to 24 in 0137a4d
| fortify.tbl <- function(model, data, ...) { | |
| if (!requireNamespace("dplyr", quietly = TRUE)) { | |
| abort("dplyr must be installed to work with tbl objects") | |
| } | |
| dplyr::collect(model) | |
| } |
Suggestions
I suggest
- Deprecate
fortify.lm(),fortify.glht(),fortify.confint.glht(),fortify.summary.glht()andfortify.cld(). Replace examples usingbroom::augment()andbroom::tidy(). - Deprecate
fortify.<sp-object>andfortify.map()after ensuringgeom_sf()supersedesgeom_map(). - Merge the docs of
fortify()toautoplot()andautolayer(), and explain how developers of some custom objects can implements these methods so that the users can use ggplot2 to visualize the objects painlessly (Mark geom_map() as superseded #3721).
Note that this issue is not very high priority as maintaining fortify() doesn't seem a heavy burden, at least at the moment. I filed this issue just because it seems we need some place to discuss to avoid confusion. Anyway, I believe it's a right move to encourage users to use broom and sf.