【问题标题】:Prevent x axis labels from moving to the top of plot when y axis is reversed当 y 轴反转时,防止 x 轴标签移动到绘图顶部
【发布时间】:2023-03-06 17:54:01
【问题描述】:

我最近更新了一些软件包,我认为它改变了我用来创建 96 孔板布局的一些代码的行为。

这是代码:

ggplot(NULL, aes(x=Column, y=Row)) +
  geom_point(data=expand.grid(seq(1, 12), seq(1,8)), 
             aes(x=Var1, y=Var2),
             color="grey90", 
             fill="white", 
             shape=21, 
             size=12) +
  coord_fixed(ratio=(13/12)/(9/8), 
              xlim=c(0.5, 12.5), 
              ylim=c(0.5, 8.5)) +
  scale_y_reverse(breaks=seq(1, 8),
                  labels=LETTERS[1:8]) +
  scale_x_continuous(breaks=seq(1, 12))

如果我不反转y轴,我对x轴没有任何问题:

ggplot(NULL, aes(x=Column, y=Row)) +
  geom_point(data=expand.grid(seq(1, 12), seq(1,8)), 
             aes(x=Var1, y=Var2),
             color="grey90", 
             fill="white", 
             shape=21, 
             size=12) +
  coord_fixed(ratio=(13/12)/(9/8), 
              xlim=c(0.5, 12.5), 
              ylim=c(0.5, 8.5)) +
  scale_y_continuous(breaks=seq(1, 8),
                  labels=LETTERS[1:8]) +
  scale_x_continuous(breaks=seq(1, 12))

寻找一种在不弄乱 x 轴的情况下生成 y 轴反转图的方法。 作为奖励,我一直在尝试想出一种方法,使点的大小与图形的大小一起缩放,以便在缩小绘图大小时它们不会重叠:

【问题讨论】:

    标签: r ggplot2


    【解决方案1】:

    反过来是由于笛卡尔平面是如何实现的。为避免这种情况,请改用相反的ylim = c(8.5, 0.5):

    ggplot(NULL, aes(x=Column, y=Row)) +
      geom_point(data=expand.grid(seq(1, 12), seq(1,8)), 
                 aes(x=Var1, y=Var2),
                 color="grey90", 
                 fill="white", 
                 shape=21, 
                 size=12) +
      coord_fixed(ratio=(13/12)/(9/8), 
                  xlim=c(0.5, 12.5), 
                  ylim=c(8.5, 0.5)) +  
      scale_y_reverse(breaks=seq(1, 8),
                      labels=LETTERS[1:8]) +
      scale_x_continuous(breaks=seq(1, 12))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多