Skip to content

sec.axis with scale_*_log10 #1992

Closed
Closed
@pnolain

Description

@pnolain

Hi,

I have been trying to plot continuous data with a log-scaled x-axis and a secondary x-axis in order to display ticks values in another unit.
It seems to me that the ticks positions of this secondary axis are not correctly computed.

Here is a reproducible example:

foo <- tibble(x = exp(seq(log(0.001), log(1000), length.out = 100)), y = x/(1+x))

ggplot(foo, aes(x, y))+
  geom_point()+
  scale_x_log10(name = "Unit A",
                breaks = c(0.001, 0.01, 0.1, 1, 10, 100, 1000),
                sec.axis = sec_axis(~. * 100, name = "Unit B", 
                                    labels = derive(),
                                    breaks = derive()))

sec_axis1
Considering the transformation (x * 100), ticks positions do not correspond.

Also, dup_axis() does not duplicate the original axis:

ggplot(foo, aes(x, y))+
  geom_point()+
  scale_x_log10(name = "Unit A",
                breaks = c(0.001, 0.01, 0.1, 1, 10, 100, 1000),
                sec.axis = dup_axis())

sec_axis2

Am I doing something wrong?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions