ggplot刻面-删除空的x轴标签 [英] ggplot faceting - remove empty x-axis labels
本文介绍了ggplot刻面-删除空的x轴标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在文章除了使用数据的特定子集删除一些行之外.
I' using faceting following this article except for using a certain subset of the data removing some rows.
# create a dataset
specie=c(rep("sorgho" , 3) , rep("poacee" , 3) , rep("banana" , 3) , rep("triticum" , 3) )
condition=rep(c("normal" , "stress" , "Nitrogen") , 4)
value=abs(rnorm(12 , 0 , 15))
data=data.frame(specie,condition,value)
# remove some rows
data=data[c(1:2,5:6,7,9,11:12),]
# Grouped
ggplot(data, aes(fill=condition, y=value, x=specie)) +
geom_bar(position="dodge", stat="identity")
# Faceting
ggplot(data, aes(y=value, x=specie, color=specie, fill=specie)) +
geom_bar( stat="identity") +
facet_wrap(~condition)
这给出了预期的以下绘图.我需要从下面的每个图中删除空标签-例如,首先是sorgho
,第二是poacee
和triticum
,依此类推.
This gives the following plot as expected. I need to remove the empty labels from each of the plots below - for example, sorgho
from first, poacee
and triticum
from second and so on.
推荐答案
您需要将scales
参数添加到facet_wrap()
.尝试
You need to add the scales
argument to facet_wrap()
. Try
# Faceting
ggplot(data, aes(y=value, x=specie, color=specie, fill=specie)) +
geom_bar( stat="identity") +
facet_wrap(~condition, scales = "free")
这篇关于ggplot刻面-删除空的x轴标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文