【问题标题】:How to set equal panel horizontal space when use scale = "free_y"?使用 scale = "free_y" 时如何设置相等的面板水平空间?
【发布时间】:2019-04-11 02:36:18
【问题描述】:
set.seed(3)

data <- tibble(Group = c(rep("g1", 10), rep("g2", 10), rep("g3", 10)), 
    Value = c(runif(10, min = 1, max=5), runif(10, min = 1, max=5), runif(10, min = -5, max=5)))

ggplot(data, aes(Group, Value)) + 
    geom_point() + 
    facet_wrap(~ Group, scales = "free")

你可以看到当y带有小数/负值时,空间变大了。

【问题讨论】:

    标签: r ggplot2 facet-wrap


    【解决方案1】:

    您可以设置fixed width for your y-axis labels

    ggplot(data, aes(Group, Value)) + 
      geom_point() + 
      facet_wrap(~ Group, scales = "free") +
      scale_y_continuous(labels = function(label) sprintf("%10.1f", label))
    

    或者用coor_flip()翻转剧情

    ggplot(data, aes(Group, Value)) + 
      geom_point() + 
      facet_wrap(Group ~ ., scales = "free") +
      coord_flip()
    

    reprex package (v0.2.1.9000) 于 2019 年 4 月 10 日创建

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-24
    • 2017-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-13
    • 2016-08-12
    • 2019-06-11
    相关资源
    最近更新 更多