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
Export guide_axis() and consider improvements #3322
Currently we have no equivalent to guide_legend() for axes (there is an non-exported guide_axis() but it draws the axes rather than describing their parameters). We should have an exported guide object to make it possible to have new types of axes.
The build in guide_axes() also needs to gain better tools for handling long labels:
Should haveangle parameter which handles all related theme settings
Should optionally trim overlapping labels by starting and either end and bisecting inwards (cf check.overlap = TRUE in grid.text()
Should be able to draw multiple lines of labels, alternating the position to avoid overlaps
And generally look at what vega-lite does for other ideas of useful parameters.
I still have to (provided all agree this is a good idea)
Refactor scale and guide code to treat position guides like other guides so they can be specified within scale_x_*(), scale_y_*(), sec_axis(), and guides()
Refactor Coord code to use guides the guides specified in scale_x_*(), scale_y_*(), sec_axis(), and guides() instead of using draw_axis()
Collect input on what (if any) improvements should go in guide_axis(), or if they should go in some other guide function (guide_axis_fancy(), or the like)
I've gotten this to work two ways now, and I would be grateful for some opinions on how best to go about things moving forward.
Getting guide specifications from the position Scales to Coord$render_axis_(h|v)() is not trivial. Both versions I have working use the Layout to coordinate panel guides, which (like the other guides) are resolved and trained at draw time (i.e., ggplot_gtable()). The Coord is responsible for generating a set of guides that it will receive in Coord$render_axis_(h|v)(), much like it does with panel_params.
I've gotten to versions to work (i.e., pass CMD check with no visual changes), one of which "injects" the panel guides into panel_params$guides in Layout$render() ( master...paleolimbot:issue-3322-guide-axis-panel-params ), and the other of which adds a panel_guides argument to Coord$render_axis_(h|v)() and Facet$draw_panels() ( master...paleolimbot:issue-3322-guide-axis-layout ). The first one I think is way better since it doesn't result in breaking any extensions of Facets or Coords.
It might be possible to avoid any changes outside CoordCartesian (as well as some other guide code) if the guides were generated at build time, but then they wouldn't have access to the same things that the other guides do (layers, default mapping, global guides list).
I suppose I'm curious whether having the Layout coordinate panel guides is appropriate, whether the internal changes in the other guide code that was required to make this work are likely to have effects in other places, and whether or not it would be more prudent to clean up the guide code first (#3329).
I think this is the best place for my current thoughts on design, although if @hadley@thomasp85 and/or @clauswilke can think of a more appropriate place to discuss, let me know! These are my current thoughts in how to get user information about the position guides and get it to where the guides are drawn:
User-facing guide code
Guides that represent one scale should use the current infrastructure for specifying guides (i.e., scale_(x|y)_*(guide = ...) / guides((x|y) = ...)). The only difference from other guide code is that I think the default should be waiver() in the scale functions so that the coordinate system can pick the default guide.
Guides that represent more than one scale (e.g., guide_grid()) should be specified in the coord_*() constructor. This is already (sort of) the case for the guide_graticule() in coord_sf(), and I don't see any reason that we need to add any arguments to other coords at this time, since there really isn't any reason to cutomize the guide_grid() that can't already happen in the theme settings. Other panel guides are currently possible as layers (like annotation_logticks() or ggspatial::annotation_scale())...the only difference is that layers do not have access to the theme at draw time.
Internal guide code
Currently, guides are resolved, trained, exposed to the layers (to draw the glyphs), and turned into grobs at draw time (i.e., in ggplot_gtable()). I don't see any reason that this can't be the case for position guides as well.
Currently, all guides have exactly one position defined by the theme(). This should remain the case for the current guide code, but for position guides I think that guides should have a vector of positions so that code like guide_graticule(position = c("left", "bottom", "foreground")) and guide_axis(position = c("left", "right")) is possible.
Currently, all guides are trained with one scale and one scale only. This won't work for all position guides, which I think should be trained using a list of scales (just like that passed to Stat$compute_*()). This implies a different training process for position guides, which I think is necessary anyway. From much experimentation trying to get position scales/guides to survive the existing guide code, I think that new training code should be written, and eventually the rest of the guides should switch to using it. Because position guides are going to need separate training code, I think it makes sense to write them as ggproto() objects whose state is internal (like scales).
Details
Guide<- ggproto(
"Guide", NULL,
title=NULL,
position=NULL,
aesthetics=NULL,
data=NULL,
# I *think* this is enough information to perform the merge externally# NULL = never mergehash=function(self, scale) {
# title <- scale$make_title(guide$title %|W|% scale$name %|W|% labels[[output]])# digest::digest(list(title, self$aesthetics, class(self), scale$get_labels())NULL
},
# encompases the current guide_train() and guide_geom()train=function(scales, layers, default_mapping) {
# self$data <- ...# invisible(self$data)
stop("Not implemented", call.=FALSE)
},
# position is because guides may look different depending on where they are# drawn. It is the caller's responsibility to put the grob in the# right placedraw=function(self, theme, coord, position=NULL) {
stop("Not implemented", call.=FALSE)
}
)
Position guides should be resolved by the coordinate system and added to the panel_params as the guides element. This happens at draw time rather than build time, so it needs to be a new method in the Coord. They should go in the panel_params because they are already everywhere the guides are drawn (i.e., no new arguments!). We are also narrowing in to a point where there is a common structure to panel_params for all coords ($x and $y will soon be scale-like objects always, and $guides will be a list() of trained guides).
The Coord should also train the guides, but maybe not in the same place as resolving them. This mostly reflects different information requirements and helps keep all the functions short. Also, this means that coordinate systems that don't participate in the new system are left alone.
The Layout will have to pass the guides, layers, and default_mapping to these methods. These are all available in ggplot_gtable(), which calls the method.
Does this in any way address the problem that geoms (or stats?) may need access to the trained scales (#3116)? Could they now get that access through the coord, at draw time?
The coord would still only deal with position scales. I've since figured out a way to get access to the non position scales...I forgot to update the issue.
Reflecting on this over the weekend, I now feel that I should avoid ggproto() and guide_grid(), focusing only on x and y guides. They will get trained slightly differently but I think they can use S3 until all the guides are switched over.
Activity
paleolimbot commentedon May 14, 2019
I spent about a day and a half on this, and wanted to leave a few things here for when I pick it back up again. So far I've:
guide_axis()todraw_axis(), since that's what the current version actually does (creates a grob)guide_axis()implementation that mimicsguide_legend()and changeddraw_axis()to create a guide, train it, then draw it.https://github.com/paleolimbot/ggplot2/blob/0267a0aa48863b119f8288f95eac6fe87d89d95f/R/guides-axis.r#L125-L256
I still have to (provided all agree this is a good idea)
scale_x_*(),scale_y_*(),sec_axis(), andguides()scale_x_*(),scale_y_*(),sec_axis(), andguides()instead of usingdraw_axis()guide_axis(), or if they should go in some other guide function (guide_axis_fancy(), or the like)For reference, the vega-lite axis label documentation, which includes an option in inward-align labels on the end.
clauswilke commentedon May 14, 2019
hadley commentedon May 14, 2019
clauswilke commentedon May 15, 2019
hadley commentedon May 15, 2019
paleolimbot commentedon May 24, 2019
I've gotten this to work two ways now, and I would be grateful for some opinions on how best to go about things moving forward.
Getting guide specifications from the position
Scales toCoord$render_axis_(h|v)()is not trivial. Both versions I have working use theLayoutto coordinate panel guides, which (like the other guides) are resolved and trained at draw time (i.e.,ggplot_gtable()). TheCoordis responsible for generating a set of guides that it will receive inCoord$render_axis_(h|v)(), much like it does withpanel_params.I've gotten to versions to work (i.e., pass CMD check with no visual changes), one of which "injects" the panel guides into
panel_params$guidesinLayout$render()( master...paleolimbot:issue-3322-guide-axis-panel-params ), and the other of which adds apanel_guidesargument toCoord$render_axis_(h|v)()andFacet$draw_panels()( master...paleolimbot:issue-3322-guide-axis-layout ). The first one I think is way better since it doesn't result in breaking any extensions ofFacets orCoords.It might be possible to avoid any changes outside
CoordCartesian(as well as some other guide code) if the guides were generated at build time, but then they wouldn't have access to the same things that the other guides do (layers, default mapping, global guides list).paleolimbot commentedon May 24, 2019
I suppose I'm curious whether having the
Layoutcoordinate panel guides is appropriate, whether the internal changes in the other guide code that was required to make this work are likely to have effects in other places, and whether or not it would be more prudent to clean up the guide code first (#3329).Implement immutable scales in the panel_params for CoordCartesian (#3356
paleolimbot commentedon Jun 26, 2019
I think this is the best place for my current thoughts on design, although if @hadley @thomasp85 and/or @clauswilke can think of a more appropriate place to discuss, let me know! These are my current thoughts in how to get user information about the position guides and get it to where the guides are drawn:
User-facing guide code
Guides that represent one scale should use the current infrastructure for specifying guides (i.e.,
scale_(x|y)_*(guide = ...)/guides((x|y) = ...)). The only difference from other guide code is that I think the default should bewaiver()in the scale functions so that the coordinate system can pick the default guide.Guides that represent more than one scale (e.g.,
guide_grid()) should be specified in thecoord_*()constructor. This is already (sort of) the case for theguide_graticule()incoord_sf(), and I don't see any reason that we need to add any arguments to other coords at this time, since there really isn't any reason to cutomize theguide_grid()that can't already happen in the theme settings. Other panel guides are currently possible as layers (likeannotation_logticks()orggspatial::annotation_scale())...the only difference is that layers do not have access to thethemeat draw time.Internal guide code
Currently, guides are resolved, trained, exposed to the layers (to draw the glyphs), and turned into grobs at draw time (i.e., in
ggplot_gtable()). I don't see any reason that this can't be the case for position guides as well.Currently, all guides have exactly one
positiondefined by thetheme(). This should remain the case for the current guide code, but for position guides I think that guides should have a vector of positions so that code likeguide_graticule(position = c("left", "bottom", "foreground"))andguide_axis(position = c("left", "right"))is possible.Currently, all guides are trained with one scale and one scale only. This won't work for all position guides, which I think should be trained using a list of scales (just like that passed to
Stat$compute_*()). This implies a different training process for position guides, which I think is necessary anyway. From much experimentation trying to get position scales/guides to survive the existing guide code, I think that new training code should be written, and eventually the rest of the guides should switch to using it. Because position guides are going to need separate training code, I think it makes sense to write them asggproto()objects whose state is internal (like scales).Details
panel_paramsas theguideselement. This happens at draw time rather than build time, so it needs to be a new method in theCoord. They should go in thepanel_paramsbecause they are already everywhere the guides are drawn (i.e., no new arguments!). We are also narrowing in to a point where there is a common structure topanel_paramsfor all coords ($xand$ywill soon be scale-like objects always, and$guideswill be alist()of trained guides).Details
Coordshould also train the guides, but maybe not in the same place as resolving them. This mostly reflects different information requirements and helps keep all the functions short. Also, this means that coordinate systems that don't participate in the new system are left alone.Details
Layoutwill have to pass theguides,layers, anddefault_mappingto these methods. These are all available inggplot_gtable(), which calls the method.Details
Coordhas access to trained guides in itspanel_params, which already get passed toCoord$render_*()by theFacet.Details
Thoughts? Suggestions? Modifications?
clauswilke commentedon Jun 26, 2019
Does this in any way address the problem that geoms (or stats?) may need access to the trained scales (#3116)? Could they now get that access through the coord, at draw time?
paleolimbot commentedon Jun 27, 2019
The coord would still only deal with position scales. I've since figured out a way to get access to the non position scales...I forgot to update the issue.
paleolimbot commentedon Jun 30, 2019
Reflecting on this over the weekend, I now feel that I should avoid
ggproto()andguide_grid(), focusing only onxandyguides. They will get trained slightly differently but I think they can use S3 until all the guides are switched over.lock commentedon Mar 27, 2020
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/
Make position guides customizable (tidyverse#3398, closes tidyverse#3322