我想将ggplot2图上的左侧Y轴复制到右侧,然后更改离散(分类)轴的刻度标签。在ggplot2中复制(和修改)离散轴
我读过的答案this question,但是可以看出on the package's repo page,该switch_axis_position()
功能已经从cowplot
包装中取出(作者引用GGPLOT2(即将出版?)本机功能)。
我已经在ggplot2的次轴上看到了reference页面,但是该文档中的所有示例都使用scale_y_continuous
而不是scale_y_discrete
。而且,事实上,当我尝试使用离散函数,我得到的错误:
Error in discrete_scale(c("y", "ymin", "ymax", "yend"), "position_d", :
unused argument (sec.axis = <environment>)
反正是有与GGPLOT2做到这一点?即使是完全黑客的解决方案也足以满足我的需求。提前致谢。 (下面的MRE)
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))
看的'源scale_y_discrete'有用于指定所述副轴没有选项/参数。所以任何解决方案可能都必须是黑客。 – SymbolixAU