Consider the following code:
library(ggplot2)
data = data.frame(x = c(1, 2,
3, 4,
5, 6),
label = c("foo", "bar",
"bar", "baz",
"baz", "boo"),
type = c(1, 1,
2, 2,
3, 3))
ggplot(data, aes(x = x, y = c(1))) +
labs(x = "", y = "") +
theme_bw() +
facet_wrap(~ type, ncol = 1, scales = "free_x") +
scale_x_discrete(aes(breaks = x, labels=label), limits = 1:6) +
geom_point()
它生成了该图像: 问题是我的
scale_x_discrete()
被忽略了。我想让每个facet的x轴缩放显示data$label
标签,但仅在有数据时才显示。换句话说,我想要像这样的东西,但在一个单独的图表上:
我该怎么做?
ggplot(data, aes(x = x, y = c(1)))
而不是ggplot(data, aes(x = x, y = c(0)))
。 - mpalanco