如何使所有轴刻度在ggplot2中朝内(包括辅助轴)

时间:2019-07-02 10:19:12

标签: r ggplot2 themes axis

出于美学目的,我希望我的所有轴刻度都朝内而不是朝外,包括副轴的轴刻度,同时使副轴值保持空白。我可以为我的所有轴执行此操作(请参见代码),但是,有没有办法让我的辅助轴值保持“空白”而不是重复?

ggplot(matrix, aes(x)) + 
  geom_line(aes(y = bn0.5), linetype = "solid") +
  geom_line(aes(y = bn0.7), linetype = "longdash") +
  geom_line(aes(y = bn0.9), linetype = "twodash") +
  scale_x_continuous(breaks = seq(0.1, 0.9, 0.1),
                     sec.axis = dup_axis()) +
  scale_y_continuous(breaks = seq(0.01, 0.06, 0.02),
                     sec.axis = sec_axis(~ . * 1, breaks = seq(0.01, 0.06, 0.02), )) +
  xlab("1 - d") +
  ylab("macroHR(loo)") +
  theme(panel.grid.major = element_line(size = 0.5, linetype = 'dashed', colour = "grey90"), 
        panel.grid.minor = element_line(size = 0.25, linetype = 'dashed', colour = "grey90"),
        panel.background = element_rect(fill = 'white', colour = 'grey20'),
        axis.ticks.length=unit(-0.25, "cm"),
        axis.text.x = element_text(margin=unit(c(0.5,0.5,0.5,0.5), "cm")), 
        axis.text.y = element_text(margin=unit(c(0.5,0.5,0.5,0.5), "cm")))

现在,我做了一个解决方法,并将辅助轴设置为x和y轴的副本。但是现在,我需要删除辅助轴值,该怎么做?

1 个答案:

答案 0 :(得分:0)

Nvm,我已经通过使用axis.text.y.right = element_blank()找到了解决方案,对于x.top也是如此