I am trying to follow the instructions here on how to create a dual y-axis plot (yes, I know). My code is here.
我试图按照这里的说明来创建一个双y轴图(是的,我知道)。我的代码在这里。
However, in the output some of the major grid lines are slightly misaligned (see the red box), whereas some of them are perfectly aligned. I am not sure what is causing this dilation of one of the plots. I rewrote the code on that site to understand it better and have possibly introduced a bug somewhere.
然而,在输出中,一些主要的网格线有轻微的偏差(看红色的方块),而有些则是完全对齐的。我不知道是什么导致了其中一个情节的扩大。我重写了该站点上的代码,以便更好地理解它,并可能在某个地方引入了一个bug。
An easy fix would be to turn off grid lines on one of the plots, but that seems to be hiding the problem rather than fixing it.
一个简单的解决办法是在其中一个地块上关闭网格线,但这似乎隐藏了问题,而不是解决问题。
Edit:
I tried running the original code here unchanged, and I ran into the following error on line 130.
我尝试在这里运行原始代码不变,然后在第130行中遇到了下面的错误。
> ticks$grobs[[1]]$x <- ticks$grobs[[1]]$x - unit(1, "npc") + tml
Error in Ops.unit(ticks$grobs[[1]]$x, unit(1, "npc")) :
both operands must be units
So, I cannot check if the issue is a bug that I have introduced while transcription.
所以,我不能检查这个问题是不是我在转录过程中引入的bug。
1 个解决方案
#1
1
Your code in the gist
doesn't run (and it's also a bit complicated).
您的代码在gist中没有运行(而且它也有点复杂)。
To understand why the lines aren't aligned, consider this example:
要理解为什么这些行没有对齐,请考虑以下示例:
- axis1: range: 0 - 1. The value of 0.5 is mid-way between 0 and 1.
- axis1:范围:0 - 1。0。5的值在0和1之间。
- axis2: range: 0 - 10. The value of 5 is mid-way between 0 and 10.
- axis2:范围:0 - 10。5的值在0和10之间。
Now in your graph you have (something like)
在你的图表中
- axis1: range: 0 - 1.1. The value of 0.5 is 0.5/1.1 = 0.45 between 0 and 1.
- axis1:范围:0 - 1.1。0.5的值为0.5/1.1 = 0.45,介于0和1之间。
- axis2: range: 0 - 10.1. The value of 5 is 5/10.1 = 0.495 between 0 and 10.
- axis2:范围:0 - 10.1。5的值是5/10.1 = 0.495,在0到10之间。
- Result: mis-aligned lines.
- 结果:mis-aligned线。
You shouldn't add a constant to each axis, the value needs to be proportional to the scale.
你不应该在每一个轴上加上一个常数,这个值需要与这个比例成比例。
#1
1
Your code in the gist
doesn't run (and it's also a bit complicated).
您的代码在gist中没有运行(而且它也有点复杂)。
To understand why the lines aren't aligned, consider this example:
要理解为什么这些行没有对齐,请考虑以下示例:
- axis1: range: 0 - 1. The value of 0.5 is mid-way between 0 and 1.
- axis1:范围:0 - 1。0。5的值在0和1之间。
- axis2: range: 0 - 10. The value of 5 is mid-way between 0 and 10.
- axis2:范围:0 - 10。5的值在0和10之间。
Now in your graph you have (something like)
在你的图表中
- axis1: range: 0 - 1.1. The value of 0.5 is 0.5/1.1 = 0.45 between 0 and 1.
- axis1:范围:0 - 1.1。0.5的值为0.5/1.1 = 0.45,介于0和1之间。
- axis2: range: 0 - 10.1. The value of 5 is 5/10.1 = 0.495 between 0 and 10.
- axis2:范围:0 - 10.1。5的值是5/10.1 = 0.495,在0到10之间。
- Result: mis-aligned lines.
- 结果:mis-aligned线。
You shouldn't add a constant to each axis, the value needs to be proportional to the scale.
你不应该在每一个轴上加上一个常数,这个值需要与这个比例成比例。