Description Usage Arguments Details Author(s) Examples
View source: R/generate_shifted_axis.R
Generate a dataframe and geoms to add an auxiliary axis to a plot
1 2 | generate_shifted_axis(limits, steps, other_ax_steps, axis, tick_sz = 0.7,
intercept = 0)
|
limits |
A vector with two elements defining the limits of your axis. |
steps |
A single integer or double specifying how far the ticks of the new auxiliary axis should be apart, in the unit of the axis. |
other_ax_steps |
A single integer or double specifying the how far the ticks of the orthogonal axis are apart, in the unit of the orthogonal axis. Is used to determine the size of the ticks. See details. |
axis |
A character indicating which axis should be generated. Can be set to "x" or "y". |
tick_sz |
Determines the size of the ticks, which is expressed as percentage of the other axis's steps. Defaults to .7. See details. |
intercept |
A single integer or double specifying where the new auxiliary axis should cross the orthogonal axis, in units of the orthogonal axis. Defaults to 0. |
The main output of the function is a dataframe that contains all the
information needed to build an auxiliary axis with tick marks for
your plot which cross the orthogonal axis at a specified intercept.
Simultaneously, generate_shifted_axis()
will print the code
you need to add to your plot to insert your newly created auxiliary
axis. Note that you need to replace 'YOURDF'
with the name of
the object you saved the function's output to.
As you can tell from this printed output, it is not a true axis that
is created, but instead a combination of geom_hline
(or geom_vline
) and geom_segment
to mimic an axis. You
may want to add theme(axis.line = element_blank())
or even
theme(axis.line = element_blank(), axis.ticks = element_blank())
to your plot to get rid of the usual axis lines.
Note that the axis text is not shifted, but stays with the actual axis, because the function is optimised for readable EEG plots. See the example folder on GitHub.
As the ticks are in fact plotted with x and y coordinates, the tick
size is computed relative to the size of the steps you auxiliary
axis is orthogonal to. That is, if you are creating a y-axis, the
ticks of your x-axis are spaced 200 units apart and tick_sz
is set to 1, the ticks will be exactly as long as the space between
two ticks of the x-axis.
Currently, this generate_shifted_axis()
assumes that both of
your axes are numerical and is at an experimental stage. Feeding it
with anything that widely differs from plots roughly resembling an
EEG data plot or twisting the limits so they don't correspond to
your plot's actual parameters may lead to quirky results.
Juliane Tkotz juliane.tkotz@hhu.de
1 2 3 | x_ticks <- generate_shifted_axis(
c(-200, 1100), 200, 1, "x"
)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.