ggplot2分类x轴的不同构面宽度 [英] ggplot2 different facet width for categorical x-axis
本文介绍了ggplot2分类x轴的不同构面宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在绘制分类数据的不同方面:
I have am plotting different facets of categorical data:
df <- as.data.frame(as.factor(c("A","B","C","D","E","F")))
names(df) <- "Xvar"
df$Yvar <- c(2,1,4,5,3,7)
df$facet <- c(rep("facet 1",2),rep("facet 2",4))
ggplot(df, aes(x=Xvar, y=Yvar, group=1)) +
geom_line() +
facet_wrap(~facet, scales="free_x")
如何使仅包含两个类别的构面1成为包含四个类别的构面2大小的一半? IE.每个小平面的宽度与x轴分类数据点的数量成正比吗?我尝试scales="free_x"
无济于事.
How can I make it such that facet 1 consisting of only two categories is half the size of facet 2 containing four categories? I.e. that the width of each facet is proportional to the number of categorical x-axis data points? I tried scales="free_x"
to no avail.
推荐答案
如果您愿意使用facet_grid
而不是facet_wrap
,则可以使用space
参数来实现.
If you're willing to use facet_grid
instead of facet_wrap
, you can do this with the space
parameter.
ggplot(df, aes(x=Xvar, y=Yvar, group=1)) +
geom_line() +
facet_grid(~facet, scales="free_x", space = "free_x")
这篇关于ggplot2分类x轴的不同构面宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文