I wanted to show log tick marks on both the primary and secondary axes in a log-log plot using ggplot2
, but I couldn't get it to work. I've posted a question on Stack Overflow, and based on the answer, it seems the issue isn't on my end. However, I'm unsure whether this behavior warrants a bug report or a feature request on GitHub. What do you think? Is this a bug, or simply unsupported?
R
version: 4.4.2
ggplot2
version: 3.5.2
Here's a simple log-log plot:
library(ggplot2)
ggplot() +
scale_x_log10(limits=c(10^0, 10^4), sec.axis=dup_axis()) +
scale_y_log10(limits=c(10^-4, 10^0), sec.axis=dup_axis()) +
geom_function(fun=function(x) 1/x)
When I add "axis_logticks"
as a guide, it fails with the following message:
ggplot() +
scale_x_log10(limits=c(10^0, 10^4), guide="axis_logticks", sec.axis=dup_axis()) +
scale_y_log10(limits=c(10^-4, 10^0), guide="axis_logticks", sec.axis=dup_axis()) +
geom_function(fun=function(x) 1/x)
Error in seq.default(start, end, by = 1) : 'to' must be a finite number
Setting the guides separately works for the primary x- and y-axes:
ggplot() +
scale_x_log10(limits=c(10^0, 10^4), sec.axis=dup_axis()) +
scale_y_log10(limits=c(10^-4, 10^0), sec.axis=dup_axis()) +
guides(x="axis_logticks", y="axis_logticks") +
geom_function(fun=function(x) 1/x)
However, it fails again with the secondary x-axis, giving the same error message:
ggplot() +
scale_x_log10(limits=c(10^0, 10^4), sec.axis=dup_axis()) +
scale_y_log10(limits=c(10^-4, 10^0), sec.axis=dup_axis()) +
guides(x="axis_logticks", y="axis_logticks", x.sec="axis_logticks") +
geom_function(fun=function(x) 1/x)
Interestingly enough, with the secondary y-axis, it doesn't throw an error, but the secondary y-axis only partially has logticks:
ggplot() +
scale_x_log10(limits=c(10^0, 10^4), sec.axis=dup_axis()) +
scale_y_log10(limits=c(10^-4, 10^0), sec.axis=dup_axis()) +
guides(x="axis_logticks", y="axis_logticks", y.sec="axis_logticks") +
geom_function(fun=function(x) 1/x)