Duplicating (and modifying) discrete axis in ggplot2 : <p>I want to duplicate the left-side Y-axis on a ggplot2 plot onto the right side, and then change the tick labels for a discrete (categorical) axis.</p>

<p>I've read the answer to <a href="https://stackoverflow.com/questions/40134648/duplicating-discrete-axis-in-ggplot2">this question</a>, however as can be seen <a href="https://github.com/wilkelab/cowplot/blob/d10f9cad3123594e2925e680b8b2b59856c8833f/vignettes/axis_position.Rmd" rel="noreferrer">on the package's repo page</a>, the <code>switch_axis_position()</code> function has been removed from the <code>cowplot</code> package (the author cited (forthcoming?) native functionality in ggplot2).</p>

<p>I've seen the <a href="http://ggplot2.tidyverse.org/reference/sec_axis.html" rel="noreferrer">reference</a> page on secondary axes in ggplot2, however all the examples in that document use <code>scale_y_continuous</code> rather than <code>scale_y_discrete</code>. And, indeed, when I try to use the discrete function, I get the error:</p>

<pre><code>Error in discrete_scale(c("y", "ymin", "ymax", "yend"), "position_d",  : 
unused argument (sec.axis = &lt;environment&gt;)
</code></pre>

<p>Is there anyway to do this with ggplot2? Even a completely hacked solution will suffice for me. Thanks in advance. (MREs below)</p>

<pre><code>library(ggplot2)

# Working continuous plot with 2 axes
ggplot(mtcars, aes(cyl, mpg))  + 
    geom_point() + 
    scale_y_continuous(sec.axis = sec_axis(~.+10))


# Working discrete plot with 1 axis
ggplot(mtcars, aes(cyl, as.factor(mpg)))  + 
    geom_point() 


# Broken discrete plot with 2 axes
ggplot(mtcars, aes(cyl, as.factor(mpg)))  + 
    geom_point() +
    scale_y_discrete(sec.axis = sec_axis(~.+10))
</code></pre>
