-
Notifications
You must be signed in to change notification settings - Fork 1
Add aspect ratio support in ggdesplot (not completely sure) #15
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
Merged
kwstat
merged 12 commits into
kwstat:main
from
SchmidtPaul:claude/add-aspect-ratio-support-011CV5vEmJFGwgUMNcAhERMv
Dec 5, 2025
Merged
Add aspect ratio support in ggdesplot (not completely sure) #15
kwstat
merged 12 commits into
kwstat:main
from
SchmidtPaul:claude/add-aspect-ratio-support-011CV5vEmJFGwgUMNcAhERMv
Dec 5, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Adds support for the 'aspect' parameter in ggdesplot() to create true-scale field maps, bringing feature parity with the lattice version. Changes: - Added 'aspect' parameter to ggdesplot() function signature - When aspect is specified, uses coord_fixed(ratio=aspect, expand=FALSE) - When aspect is NULL, uses coord_cartesian(expand=FALSE) as before - Updated desplot() to pass ... arguments to ggdesplot(), allowing aspect and other parameters to flow through Usage example: ggdesplot(yates.oats, yield ~ col*row, aspect=511/176) This allows users to create plots with accurate spatial proportions matching the actual field dimensions.
Adds support for the 'aspect' parameter in ggdesplot() to create true-scale field maps, bringing feature parity with the lattice version. Changes: - Added 'aspect' parameter to ggdesplot() function signature - Converts aspect ratio from lattice convention (width/height) to ggplot2 convention (height/width) by inverting: coord_fixed(1/aspect) - When aspect is NULL, uses coord_cartesian(expand=FALSE) as before - Updated desplot() to pass ... arguments to ggdesplot(), allowing aspect and other parameters to flow through Usage example: ggdesplot(yates.oats, yield ~ col*row, aspect=511/176) This allows users to create plots with accurate spatial proportions matching the actual field dimensions and the lattice version output.
…v' of https://github.com/SchmidtPaul/desplot into claude/add-aspect-ratio-support-011CV5vEmJFGwgUMNcAhERMv
Adds support for the 'aspect' parameter in ggdesplot() to create true-scale field maps, bringing feature parity with the lattice version. Changes: - Added 'aspect' parameter to ggdesplot() function signature - Uses coord_fixed(ratio=aspect, expand=FALSE) when aspect is specified - Both lattice and ggplot2 use the same convention: aspect = height/width - When aspect is NULL, uses coord_cartesian(expand=FALSE) as before - Updated desplot() to pass ... arguments to ggdesplot(), allowing aspect and other parameters to flow through Usage example: ggdesplot(yates.oats, yield ~ col*row, aspect=511/176) This allows users to create plots with accurate spatial proportions matching the actual field dimensions.
…v' of https://github.com/SchmidtPaul/desplot into claude/add-aspect-ratio-support-011CV5vEmJFGwgUMNcAhERMv
…v' of https://github.com/SchmidtPaul/desplot into claude/add-aspect-ratio-support-011CV5vEmJFGwgUMNcAhERMv
Owner
|
I'm adding a better example to desplot.R file: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds support for the
aspectparameter inggdesplot()to control cell aspect ratios for true-scale field maps.Note that this PR is also kind of an issue - see "Observation on Lattice Behavior" below
The aspect ratio feature is documented for the lattice version with the note "To get a map of a field with a true aspect ratio (lattice version only), include 'aspect=ylen/xlen'". This PR removes the "lattice version only" limitation by implementing aspect ratio support for the ggplot2 version.
Changes
R/ggdesplot.R:
aspectparameter to function signature (line 81)coord_fixed(ratio=aspect, expand=FALSE)when aspect is specified (lines 530-536)aspectisNULL, usescoord_cartesian(expand=FALSE)as before (default behavior unchanged)R/desplot.R:
ggdesplot()to pass...arguments through (line 330)aspect(and other future parameters) to flow fromdesplot(gg=TRUE)toggdesplot()Implementation Details
The implementation uses
coord_fixed(ratio=aspect)whereaspectrepresents the height/width ratio. Both lattice and ggplot2 use this same convention:aspect=1→ square cellsaspect=2→ cells 2x taller than wideaspect=0.5→ cells 2x wider than tallObservation on Lattice Behavior
During development and testing, I observed something unexpected: when using
ggdesplot()withaspect=1, the cells appear square (as expected). However, when using the lattice versiondesplot()withaspect=1, the cells do not appear square.I wanted to bring this to your attention because:
aspectparameter is intended to work in the lattice versionThe ggplot2 implementation uses
coord_fixed(ratio=aspect)which directly controls the ratio of y-axis units to x-axis units, creating cell shapes that correspond to the aspect value as I understand it.Reprex
Created on 2025-11-14 with reprex v2.1.1
Benefits
ggdesplot()