使用scale = "free_y"时如何设置水平面板相等space?
How to set equal panel horizontal space when use scale = "free_y"?
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 的值为 decimal/negative 时,space 变大了。
你可以设置一个
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-04-10 创建
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 的值为 decimal/negative 时,space 变大了。
你可以设置一个
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-04-10 创建