【问题标题】:How to make all axis ticks face inwards in ggplot2 including secondary axis如何使 ggplot2 中的所有轴刻度都朝内,包括辅助轴
【发布时间】:2019-07-02 10:19:12
【问题描述】:

出于美学目的,我希望我的所有轴刻度都朝内而不是朝外,包括辅助轴的轴刻度,同时保持辅助轴值为空白。我可以为我的所有轴做到这一点(见代码),但是,有没有办法让我的辅助轴值“空白”而不是重复?

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 轴的副本。但是现在,我需要删除我的辅助轴值,该怎么做?

【问题讨论】:

    标签: r ggplot2 themes axis


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-08
      • 2014-12-09
      相关资源
      最近更新 更多