簡體   English   中英

R 多個繪圖,具有通用 y 軸縮放和共享 x 軸 label

[英]R multiple plots with common y-axis scaling and shared x-axis label

這是我在這里的第一個問題。 請善待(R-)新手:)

我正在嘗試從不同的數據框中排列多個圖,以便它們共享一個共同的 y 軸,並且 x 軸標簽/數字僅顯示在底部 plot 下方。

我的數據框由以下列組成:測量時間( messzeitpunkt_s )、平均值( z_mean )、置信區間的上限( z_ci_up )、置信區間的下限( z_ci_low )。

這是我嘗試過的:

  1. 我創建了要堆疊在另一個上的圖:

`

p_neutral <- ggplot(neutral_all_mean_ci, aes(messzeitpunkt_s, z_mean, colour = " Mittelwert ")) +
  theme_bw()+
  geom_ribbon(aes(messzeitpunkt_s, ymax = z_ci_up, ymin = z_ci_low), fill = "#FCE5D7", alpha=0.8) +
  labs(x = "Messzeit [s]",y = "Neutral")+
  geom_line() +
  geom_line(aes(y = z_ci_low, colour =" 95% CI ")) +
  geom_line(aes(y = z_ci_up, colour = " 95% CI ")) +
  theme(legend.position = "none") +
  scale_color_manual(values=c("#F7B383", "#3074B3", "#F7B383"))

`

我使用相同的代碼來創建繪圖p_anger、p_disgust、p_fear、p_happiness、p_sadness、p_surprise ,僅通過用anger_all_mean_ci等替換 ggplot 函數中的數據框neutral_all_mean_ci等並更改各自的標簽。

  1. 當我使用ggarrage()將它們堆疊在另一個上時:

ggarrange(p_neutral, p_anger, p_disgust, p_fear, p_happiness, p_sadness, p_surprise, ncol=1)

我最終得到了這個plot

現在我想有一個共同的 y 軸刻度(所以圖顯示相同的范圍)和 x 軸標簽/數字僅在底部 plot。

有人可以幫我嗎? 提前致謝!

歡迎來到 StackOverflow!

我認為您只能在最后一個geom_line()中使用scale_y_continuous(limits = c(-0.5, 1.5))labs(x="Messzeit [s]") ,如下所示:

p_neutral <- ggplot(neutral_all_mean_ci, aes(messzeitpunkt_s, z_mean, colour = " Mittelwert ")) +
  theme_bw()+
  geom_ribbon(aes(messzeitpunkt_s, ymax = z_ci_up, ymin = z_ci_low), fill = "#FCE5D7", alpha=0.8) + scale_y_continuous(limits = c(-0.5, 1.5)) +
  labs(x = "",y = "Neutral")+ scale_y_continuous(limits = c(-0.5, 1.5)) +
  geom_line() + labs(x="") +
  geom_line(aes(y = z_ci_low, colour =" 95% CI ")) + scale_y_continuous(limits = c(-0.5, 1.5)) + labs(x="") +
  geom_line(aes(y = z_ci_up, colour = " 95% CI ")) + scale_y_continuous(limits = c(-0.5, 1.5)) + labs(x="Messzeit [s]") +
  theme(legend.position = "none") + 
  scale_color_manual(values=c("#F7B383", "#3074B3", "#F7B383"))

讓我知道這是否可以幫助您,因為沒有您的數據集我無法運行它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM