2017-12-24 40 views
0

私はこの後に面取りを使用してarticleを使用していますが、いくつかの行を削除するデータの特定のサブセットを使用しています。ggplot faceting - 空のx軸ラベルを削除

# 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、次はpoaceetriticumなどです。

enter image description here

答えて

3

あなたはfacet_wrap()scales引数を追加する必要があります。試してみてください

# Faceting 
ggplot(data, aes(y=value, x=specie, color=specie, fill=specie)) + 
    geom_bar(stat="identity") +  
    facet_wrap(~condition, scales = "free") 
関連する問題