-
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
Missing ticks and gridlines with reciprocal transform #5310
Comments
duplicate of #5271 |
Indeed, this is fixed in the dev version already. |
@teunbrand I still have this issue using ggplot2_3.4.2.9000. Is there a newer dev version and if so how can I install it? Cheers, mce |
The automatic break calculations are horrible for this transformation, but that is more of an issue in {scales}. If you provide breaks manually it should work as intended. library(ggplot2)
utils::packageVersion("ggplot2")
#> [1] '3.4.2.9000'
ggplot(cars, aes (x = speed, y = dist)) +
geom_point() +
scale_y_continuous(trans = 'reciprocal',
breaks = c(2, 5, 10, 30, 120)) Created on 2023-07-22 with reprex v2.0.2 |
@teunbrand Hi there, just went back to this today, because I really need to make these plots now for a paper, and I still don't see any ticks or gridlines with your minimal example above. I tried versions 3.4.3, 3.4.4 and 3.4.4.9000. Any suggestions? Should we not reopen this issue, because if not this might never be fixed. Cheers, mce |
The example I showed above works with the development version of ggplot2 (3.4.4.9000). Could you show what happens if you run that example? |
@teunbrand Basically the same as your plot just without the gridlines and tickmarks on the y-axis (see attached). |
Does the plot render without any warning messages? Do you have the recent scales package (1.3.0) installed? library(ggplot2)
p <- ggplot(cars, aes (x = speed, y = dist)) +
geom_point() +
scale_y_continuous(trans = 'reciprocal',
breaks = c(2, 5, 10, 30, 120))
sc <- layer_scales(p)$y
sc$break_info()
#> $range
#> [1] 0.008333333 0.500000000
#>
#> $labels
#> [1] "2" "5" "10" "30" "120"
#>
#> $major
#> [1] 1.00000000 0.38983051 0.18644068 0.05084746 0.00000000
#>
#> $minor
#> [1] 1.00000000 0.69491525 0.38983051 0.28813559 0.18644068 0.11864407 0.05084746
#> [8] 0.02542373 0.00000000
#>
#> $major_source
#> [1] 0.500000000 0.200000000 0.100000000 0.033333333 0.008333333
#>
#> $minor_source
#> [1] 0.500000000 0.350000000 0.200000000 0.150000000 0.100000000 0.066666667
#> [7] 0.033333333 0.020833333 0.008333333 Created on 2023-12-13 with reprex v2.0.2 |
@teunbrand First of all thanks a lot for taking a look at this. And: No warnings, version of scales is 1.3.0.9000 and the break info is exactly the same as for you. |
Weird, I'll reopen this for now. The fact that the break information is the same suggests to me that the transformation and scale is fine. Because we miss the gridlines as well, it seems like the axis guide is an unlikely suspect. That leaves the view scales intermediary between scales and guides as a suspect, but I can't really investigate as I'm unable to reproduce the issue. |
Not sure if you're still not able to reproduce, but I just ran into this same thing in ggplot 3.5 today. Weirdly, I noticed the behavior depends on the choice of limits. Below, the x axis ranges from 1 to {1/5, 1/10, 1/20, 1/30}: Full reprex (edit: missed that you wanted library(ggplot2)
utils::packageVersion('ggplot2')
#> [1] '3.5.0'
make_plot <- function(denom) {
p <- data.frame(x = c(1, 1/denom), y = c(0,0)) |>
ggplot(aes(x, y)) +
scale_x_continuous(transform = 'reciprocal')
sc = layer_scales(p)$y
print(paste0('=== 1/', denom, ' ==='))
print(sc$break_info())
ggsave(paste0('~/Desktop/plot-', denom, '.png'), p, width = 5, height = 3)
}
purrr::walk(c(5, 10, 20, 30), make_plot)
#> [1] "=== 1/5 ==="
#> $range
#> [1] 0 0
#>
#> $labels
#> [1] "0"
#>
#> $major
#> [1] 0.5
#>
#> $minor
#> NULL
#>
#> $major_source
#> [1] 0
#>
#> $minor_source
#> NULL
#> [1] "=== 1/10 ==="
#> $range
#> [1] 0 0
#>
#> $labels
#> [1] "0"
#>
#> $major
#> [1] 0.5
#>
#> $minor
#> NULL
#>
#> $major_source
#> [1] 0
#>
#> $minor_source
#> NULL
#> [1] "=== 1/20 ==="
#> $range
#> [1] 0 0
#>
#> $labels
#> [1] "0"
#>
#> $major
#> [1] 0.5
#>
#> $minor
#> NULL
#>
#> $major_source
#> [1] 0
#>
#> $minor_source
#> NULL
#> [1] "=== 1/30 ==="
#> $range
#> [1] 0 0
#>
#> $labels
#> [1] "0"
#>
#> $major
#> [1] 0.5
#>
#> $minor
#> NULL
#>
#> $major_source
#> [1] 0
#>
#> $minor_source
#> NULL Created on 2024-03-08 with reprex v2.1.0 |
Just to separate a few things; if the default breaks computation yields invalid or unwieldy breaks, that is a {scales} issue. library(ggplot2)
denom <- 30
data.frame(x = c(1, 1/denom), y = c(0,0)) |>
ggplot(aes(x, y)) +
scale_x_continuous(
transform = 'reciprocal',
breaks = c(30, 1, 0.1, 0.05)
) Created on 2024-04-22 with reprex v2.1.0 If the breaks don't display even though they are appropriate, that is a {ggplot2} issue. I still haven't been able to replicate the not rendering of breaks issue, so I'm going to close this again until it can be shown how we can reproduce the issue. |
When using the reciprocal transform, no tick marks or breaks or grid lines appear on the relevant axis.
This is with ggplot2 3.4.2 using R 4.3.0 on windows 11, but has also been reported on stackoverflow with other configurations... https://stackoverflow.com/questions/76270211/loosing-grid-lines-and-ticks-upon-reciprocal-transform-in-ggplot2.
Update - this is probably the same issue as #5271, fixed in the development version
The text was updated successfully, but these errors were encountered: