2016-09-21 4 views
0

私はファセットプロットを使用していますが、プロットエリアの近くに2行のファセットラベルを移動しようとすると問題が発生します。 最小限の例を考えてみましょう:プロットエリアの近くに2行のファセットラベルを移動する

今、私たちは、次のしているプロットエリアの近くファセットラベルを移動する vjust=-0.62を追加
require(ggplot2) 

labs <- as_labeller(c(`0` = "LABEL 1", 
         `1` = "LABEL 2 HAS TWO LINES\nBECAUSE IT'S TOO LONG")) 

p <- ggplot(mtcars, aes(disp, drat)) +      
    geom_point() + 
    theme_bw() + 
    geom_hline(yintercept=2, linetype="solid") + 
    geom_vline(xintercept=50, linetype="solid") + 
    scale_x_continuous(limits=c(50,500), expand =c(0,0)) + 
    scale_y_continuous(limits = c(2, 5), expand = c(0,0)) + 
    theme(panel.border = element_blank(), 
     strip.background = element_blank(), 
     strip.text = element_text(size=9), 
     panel.grid.major = element_blank(), 
     panel.grid.minor = element_blank()) + 
    facet_wrap(~am, labeller = labs) 
p 

enter image description here

p + theme(strip.text = element_text(size=9, vjust=-0.62)) 

enter image description here

することができますように一行ラベルのLABEL 1だけがプロット領域の近くに移動されていることを確認してください。それはtです彼の問題。 私は両方のラベルが動く可能性があることを望みました。誰にも何か提案がありますか? *観測:かなりの量のファセットプロットを作成していますので、プロットを1つ1つ作成してカスタマイズするのは良い考えではありません。

+0

のためにあなたが(0,0)原点に貼り付けるLABEL1が役立つ必要があるかもしれません –

答えて

1

希望これはあなた

p + theme(strip.text = element_text(size=9, vjust=1)) 

enter image description here

関連する問題