2017-10-26 17 views
1

"Follow-up 1"、 "Follow-up 2"などの行の上にセカンダリ軸のテキスト行として表示するように、boxplotの凡例を下に追加するにはどうすればよいですか?Boxplotの凡例を軸タイトル

enter image description here

答えて

1

あなたは、この使用して面取りのようなものを意味しますか?

# Sample data 
set.seed(123); 
df <- cbind.data.frame(
     y = rnorm(20), 
     Group = sample(c("UT", "F", "T"), 20, replace = TRUE), 
     x = sample(c("Follow-up 1", "Follow-up 2"), 20, replace = TRUE)) 


# Plot 
gg <- ggplot(df, aes(x = x, y = y, fill = Group)); 
gg <- gg + geom_boxplot(); 
gg <- gg + facet_wrap(~ x, ncol = 3, scales = "free_x"); 
gg <- gg + theme(
    axis.text.x = element_blank(), 
    axis.ticks.x = element_blank()); 
gg <- gg + labs(x = "x axis label", y = "y axis label"); 

enter image description here


更新

x軸上のグループラベル

gg <- ggplot(df, aes(x = Group, y = y, fill = Group)); 
gg <- gg + geom_boxplot(); 
gg <- gg + facet_wrap(~ x, ncol = 3, scales = "free_x"); 
gg <- gg + labs(x = "x axis label", y = "y axis label"); 

enter image description here

+0

でいただきありがとうございます。私は、facet_wrap関数を使用せずに、F、T、UTをx軸のテキストとして持つソリューションを探していました。 – Mac

+0

x軸にグループラベルを含めるように答えを更新しました。これはあなたの後のことですか? –

関連する問題