本文介绍了当X值相同时,强制在一个分面网格中的两个图上的X轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有两个组的X轴大约有30个类别的数据用于刻面。我会用一些随机数据来显示它: dataf datam ggplot(datam,aes因子(x),值))+ geom_bar(stat =identity)+ facet_grid(变量〜。) 这很可爱,只是如果在该图表上再现了x轴,那么快速读取顶级分组中的类别会更容易。然而 ggplot(datam,aes(factor(x),value))+ geom_bar(stat =identity )+ facet_grid(variable〜。,scales =free) 与x轴的差异,因为我猜这两个分组的值是相同的。 我怎样才能强制顶级组再次使用X轴解决方案 尝试使用 facet_wrap 代替: $ b $ ggplot(datam,aes(factor(x),value))+ geom_bar(stat =identity)+ facet_wrap(〜variable,nrow = 2,scales =free) I have data with about 30 categories for the X axis in two groups for faceting. I will show this with some random data:dataf <- data.frame(x=c(1:30), A=rnorm(30,20,5), B=rnorm(30,15,0.5))datam <- melt(dataf, id="x")ggplot(datam, aes(factor(x), value)) + geom_bar(stat="identity") + facet_grid(variable ~ .)This is just lovely, except that it would be easier to quickly read off categories on the top grouping if the x axis was reproduced on that graph too. Howeverggplot(datam, aes(factor(x), value)) + geom_bar(stat="identity") + facet_grid(variable ~ ., scales="free")makes no difference to the x axis because, I guess, the values are the same for both groupings.How can I force the X axis to be reproduced for the top group as well of bars? 解决方案 Try using facet_wrap instead:ggplot(datam, aes(factor(x), value)) + geom_bar(stat="identity") + facet_wrap(~variable,nrow = 2,scales = "free") 这篇关于当X值相同时,强制在一个分面网格中的两个图上的X轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-18 02:21