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

问题描述 投票:2回答:1
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

r ggplot2 facet-wrap
1个回答
3
投票

你可以设置一个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-04-10(v0.2.1.9000)

© www.soinside.com 2019 - 2024. All rights reserved.