r - 使用scale = "free_y"时如何设置相等的面板水平空间?

标签 r ggplot2 facet-wrap

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 带小数/负值时,空间会变大。

enter image description here

最佳答案

您可以设置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于2019年4月10日创建(v0.2.1.9000)

关于r - 使用scale = "free_y"时如何设置相等的面板水平空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55623864/

相关文章:

r - 显示文件或对象之间的差异

r - spinplot如何绘制类似ggplot2的堆积条形图?

r - 在 ggplot2 中的各个方面注释文本

r - 按顺序为值创建 "run ID"

r - 并行运行时写入全局环境

r - 如何在 R 中使用 %.% 运算符(编辑 : operator deprecated in 2014)

r - 如何将单个 scale_color* 的不同方面映射到 ggplot2 中的不同变量?

r - ggplot直方图的难点

r - 在每个面的密度图的中心平均值上画一条线

r - 如何用ggplot删除空白面?