Skip to content
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

Fine control of axis types in axes/xaxt/yaxt #190

Merged
merged 4 commits into from
Aug 3, 2024
Merged

Conversation

zeileis
Copy link
Collaborator

@zeileis zeileis commented Aug 3, 2024

As discussed in #182 I have tried to implement character specifications of different axis types. The docs of the relevant arguments in tinyplot.default now say:

  • axes: logical or character. Should axes be drawn (TRUE or FALSE)? Or alternatively what type of axes should be drawn: "standard" (with axis, ticks, and labels; equivalent to TRUE), "none" (no axes; equivalent to FALSE), "ticks" (only ticks and labels without axis line), "labels" (only labels without ticks and axis line), "axis" (only axis line and labels but no ticks). To control this separately for the two axes, use the character specifications for xaxt and/or yaxt.
  • xaxt, yaxt: character specifying the type of x-axis and y-axis, respectively. See axes for the possible values.

Illustration:

library("tinyplot")
x <- 0:100/10
y <- sin(x)
tinyplot(y ~ x, type = "l", lwd = 2, col = "steelblue", grid = TRUE, main = 'default')
tinyplot(y ~ x, type = "l", lwd = 2, col = "steelblue", grid = TRUE, main = 'axes = "ticks"', axes = "ticks")
tinyplot(y ~ x, type = "l", lwd = 2, col = "steelblue", grid = TRUE, main = 'axes = "labels"', axes = "labels")
tinyplot(y ~ x, type = "l", lwd = 2, col = "steelblue", grid = TRUE, main = 'axes = "axis"', axes = "axis")
tinyplot(y ~ x, type = "l", lwd = 2, col = "steelblue", grid = TRUE, main = 'xaxt = "ticks", yaxt = "labels"', xaxt = "ticks", yaxt = "labels")
tinyplot(y ~ x, type = "l", lwd = 2, col = "steelblue", grid = TRUE, main = 'axes = "none", yaxt = "standard"', axes = "none", yaxt = "standard")

Different tinyplot axes definitions

Note that the plot in the bottom left panel is maybe unexpected. The reason is that frame.plot is solely selected based on axes (which is TRUE here) and not based on xaxt/yaxt. One could consider changing that but I felt that the selection of the defaults is already involved enough for a first proposal.

Feel free to make any changes or discard the PR if it's not useful (in this way).

@zeileis
Copy link
Collaborator Author

zeileis commented Aug 3, 2024

Unrelated bonus question which I noticed when preparing the example enough. Is it intentional that for the x and y sinus example from above, the following plots differ? The former is just black while the latter gets a continuous palette.

tinyplot(y ~ x)
tinyplot(sin(x) ~ x)

…/frame.plot early on in tinyplot.default, default of frame.plot is only TRUE if both axes are drawn with axis lines
@grantmcdermott
Copy link
Owner

This looks great, thanks @zeileis. I'm out with the family atm but will be and to review properly when I'm back home.

@zeileis
Copy link
Collaborator Author

zeileis commented Aug 3, 2024

While mowing the lawn I thought that it would be better to handle all defaults of axes, xaxt, yaxt, and frame.plot early on in tinyplot.default. This means that the could is in a different place than the actual drawing of the axes but the defaults could be handled in a cleaner and more intelligible way. The default of frame.plot is now NULL and then we can do: https://github.com/grantmcdermott/tinyplot/blob/axis-type/R/tinyplot.R#L532-L545

This still produces the same plots as above except for the bottom left panel which is now drawn without a frame.

Copy link
Owner

@grantmcdermott grantmcdermott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zeileis This is great. Your plot examples look very slick!

My only minor request is to make tinyAxis() its own unexported function (as you suggested).

R/tinyplot.R Outdated Show resolved Hide resolved
@zeileis
Copy link
Collaborator Author

zeileis commented Aug 3, 2024

Just in case tinyAxis() also gets called elsewhere in the future, I improved the implementation and made sure that the arguments enforced through the type do not conflict with the ... arguments.

@grantmcdermott
Copy link
Owner

Closes #182 .

@grantmcdermott grantmcdermott self-requested a review August 3, 2024 23:22
@grantmcdermott grantmcdermott merged commit 0df2aa4 into main Aug 3, 2024
3 checks passed
@grantmcdermott
Copy link
Owner

Thanks @zeileis!

@zeileis zeileis deleted the axis-type branch October 9, 2024 23:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants