-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Suggestion to change the default line end of axis lines in theme_classic #5978
Comments
Just as an illustration. Ugly corner between x/y axis lines: library(ggplot2)
p <- ggplot(mpg, aes(displ, hwy)) +
geom_point() +
theme_classic(base_line_size = 5) +
theme(axis.ticks.length = unit(5, "mm"))
p Ugly corners between axis line and ticks: p + guides(x = guide_axis(cap = "both")) Created on 2024-07-05 with reprex v2.1.0 It also doesn't quite make sense to me why there are two different shades of black here. |
Thank you for the illustrations @teunbrand. I absolutely agree. I too never got the point of the grey axis ticks in theme_classic. It would in my opinion be a lot more aesthetically pleasing with all black axis lines and tick marks. |
The two shades of black are definitely a bug in my opinion. I believe I have commented on this before but don't remember in what context. |
I'm also in favour of unifying the shade of black. With regards to theme hierarchy, almost all themes are built on top of EDIT: nevermind the suggestion would break other stuff. I can't at the moment see a clear mechanism for this. |
If it is not fixable in general, can it at least be fixed for Line 444 in b8da7af
I use |
Yes fixing |
We all agree that the axis ticks should be changed to black to match the axis lines, but I would also suggest that the axis text should be changed to black as well since all the other text elements in I totally agree that we should strive towards finding a solution, where the axis lines will look right in all complete themes and theme customizations. However, it may not be as easy as we first thought; I have come across yet another problem. In the example given for capping of the axes on the tidyverse blog, the y-axis is only capped in the upper end in a plot that uses The upper line end of the y-axis is not aligned with the tick mark of the last break, but the lower line end is perfectly aligned with the bottom of the panel background
The upper line end of the y-axis is now perfectly aligned with the tick mark of the last break, but in return the lower line end now extends beyond the bottom of the panel background
|
The {grid} system on which ggplot2 is build doesn't accommodate different With some fiddling it might be possible to offset the first/last point of a path by half a linewidth, however, there is no device consensus on how linewidth is interpreted. For example the documentation on
So there is no robust way of getting the size of half a linewidth correct all the time. Besides that, it would also make the position of the lineend graphically correct, but numerically wrong in that we couldn't do a smooth linejoin in a vector graphics editing suite with an orthogonal line, such as a tick mark or the opposite axis. I think it would probably be wisest to just accept the limitations of the graphics systems instead of pursuing perfection in this case. |
If that is the case, I completely agree with you @teunbrand. |
I've been giving the automatic inheritance some thoughts and here are some options. Option 1: Use invisible line with square lineendAs mentioned in #5978 (comment). Essentially set + Minimally invasive Option 2: Axis guide internally set square lineendAs mentioned in #5982. Essentially give + Overriding theme works as expected Option 3: Axis children get square lineendAs mentioned in #5983. Give + Minimally invasive Option 4: New parent elementThe idea here is to create an intermediate abstract theme element in between + Not too invasive |
Inspired by the newly released option to cap the axis lines (a great addition btw), I would like to suggest a cosmetic improvement to theme_classic as I believe the current default of the line end of the axis lines is not the best fit.
Theme_classic is the only original complete theme that uses axis lines. The line end of the axis lines in this theme is actually set to NULL but practically it works like the "butt" line end. The "butt" line end cuts off the very end of the lines. This is an appropriate setting for things like axis ticks etc in all other themes (as axis ticks with the "butt" line-end will align perfectly with either the panel border or panel background of all the other themes), but I don't think it is the best choice for theme_classic. In theme_classic, when the axis lines are not capped, they join together at the origin with a very ugly notch in the left lower corner as the lines are simply too short to come together correctly (unlike for instance the lines of the panel border in the themes that use that). The notch is pretty noticeable and becomes very apparent when zooming in. It gets even worse when the axis lines are capped as the notch will then be present at the upper-outer corner of both the first and last breaks of both axes.
A solution would be to change the default of the line end for the axis lines to the "square" or "round" lineend. Hereby, the two axes would join nicely at the origin when not capped and when they are capped, they would line up perfectly with the axis ticks of the first and last breaks eliminating the ugly notches. It would probably be most appropriate to change the default line end to the "square" line end as this would keep the straight lines, thereby being consistent with the form of the axis ticks and the panel border of some of the other themes etc. If there is any way to make it a default of all axis lines in ggplot2, it would probably be beneficiary to do that, so customized themes built on, say, theme_gray with added axis lines will also use the "square" line end. I can't see any downsides to make this change, but I am not an expert in either R or ggplot2, so I don't know if there is a good explanation to the current settings. I just think it would improve the aesthetics of plots made with theme_classic.
The text was updated successfully, but these errors were encountered: