我正在檢查我的資料是否正常,并創建了箱線圖 - boxplot()
、直方圖 -hist()
和ggqqplots()
(使用與ggpubr
對齊的包ggplot
)。資料顯示了使用 Raven 軟體在頻譜圖中測量的聲學引數。
對于這個專案,我需要在視覺上整齊地表示我的結果,并且我想plot_grid()
在cowplot
Package 中使用 9 列和 3 行對齊我的圖。我制作了 9 個箱線圖、9 個直方圖和 9 個ggqqplot()
物件。
當我嘗試使用該plot_grid()
函式對齊我的圖時,列印了 qqggplot() 但 hist() 和 boxplots() 物件沒有(見圖 1)。我了解到我需要將我的hist()
和boxplot()
物件轉換為 grob 物件。
我找到了一個網站(如下),該網站宣告可以使用as.glob()
或as.ggplot()
轉換我的圖表。我使用了下面這個鏈接中的資訊,但沒有成功。
uj5u.com熱心網友回復:
回答:
要將 hist() 和 boxplot() 等基礎物件轉換為 ggplot 物件以使用 plot_grid() 函式進行排列,您可以使用函式 as.ggplot()。
#Box plots
Low_Freq_Box<-as.ggplot(~boxplot(New_Acoustic_Parameters$Low.Freq))
High_Freq_Box<-as.ggplot(~boxplot(New_Acoustic_Parameters$High.Freq))
Peak_Freq_Box<-as.ggplot(~boxplot(New_Acoustic_Parameters$Peak.Freq))
Delta_Freq_Box<-as.ggplot(~boxplot(New_Acoustic_Parameters$Delta.Freq))
Peak_Time_Box<-as.ggplot(~boxplot(New_Acoustic_Parameters$Peak.Time))
Delta_Time_Box<-as.ggplot(~boxplot(New_Acoustic_Parameters$Delta.Time))
Center_Freq_Box<-as.ggplot(~boxplot(New_Acoustic_Parameters$Center.Freq))
Start_Freq_Box<-as.ggplot(~boxplot(New_Acoustic_Parameters$Start.Freq))
End_Freq_Box<-as.ggplot(~boxplot(New_Acoustic_Parameters$End.Freq))
#Histograms
Low_Freq_hist<-as.ggplot(~hist(New_Acoustic_Parameters$Low.Freq))
High_Freq_hist<-as.ggplot(~hist(New_Acoustic_Parameters$High.Freq))
Peak_Freq_hist<-as.ggplot(~hist(New_Acoustic_Parameters$Peak.Freq))
Delta_Freq_hist<-as.ggplot(~hist(New_Acoustic_Parameters$Delta.Freq))
Peak_Time_hist<-as.ggplot(~hist(New_Acoustic_Parameters$Peak.Time))
Delta_Time_hist<-as.ggplot(~hist(New_Acoustic_Parameters$Delta.Time))
Center_Freq_hist<-as.ggplot(~hist(New_Acoustic_Parameters$Center.Freq))
Start_Freq_hist<-as.ggplot(~hist(New_Acoustic_Parameters$Start.Freq))
End_Freq_hist<-as.ggplot(~hist(New_Acoustic_Parameters$End.Freq))
#QQ Plots
Low_Freq_qqplot<-ggqqplot(New_Acoustic_Parameters$Low.Freq)
High_Freq_qqplot<-ggqqplot(New_Acoustic_Parameters$High.Freq)
Peak_Freq_qqplot<-ggqqplot(New_Acoustic_Parameters$Peak.Freq)
Delta_Freq_qqplot<-ggqqplot(New_Acoustic_Parameters$Delta.Freq)
Delta_Time_qqplot<-ggqqplot(New_Acoustic_Parameters$Peak.Time)
Peak_Time_qqplot<-ggqqplot(New_Acoustic_Parameters$Delta.Time)
Center_Freq_qqplot<-ggqqplot(New_Acoustic_Parameters$Center.Freq)
Start_Freq_qqplot<-ggqqplot(New_Acoustic_Parameters$Start.Freq)
End_Freq_qqplot<-ggqqplot(New_Acoustic_Parameters$End.Freq)
#Open a new graphics window
dev.new()
#Plot the box plots, histograms, and qqplots on the same grid
plot_grid(Low_Freq_Box, High_Freq_Box, Peak_Freq_Box, Delta_Freq_Box, Peak_Time_Box, Delta_Time_Box, Center_Freq_Box, Start_Freq_Box, End_Freq_Box,
Low_Freq_hist, High_Freq_hist, Peak_Freq_hist, Delta_Freq_hist, Peak_Time_hist, Delta_Time_hist, Center_Freq_hist, Start_Freq_hist, End_Freq_hist,
Low_Freq_qqplot, High_Freq_qqplot, Peak_Freq_qqplot, Delta_Freq_qqplot, Delta_Time_qqplot, Peak_Time_qqplot, Center_Freq_qqplot, Start_Freq_qqplot, End_Freq_qqplot,
labels=c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27"),
ncol=9, nrow=3,
align="hv",
label_size = 9,
axis = "tblr")
圖表:
uj5u.com熱心網友回復:
您是否嘗試過使用包的grid.arrange()
功能gridExtra
?
這里有一個關于 Cran的例子
對你來說,它看起來像這樣
library(gridExtra)
library(grid)
library(ggplot2)
grid.arrange(Low_Freq_Box, High_Freq_Box, Peak_Freq_Box, Delta_Freq_Box, Peak_Time_Box, Delta_Time_Box, Center_Freq_Box, Start_Freq_Box, End_Freq_Box,
Low_Freq_hist, High_Freq_hist, Peak_Freq_hist, Delta_Freq_hist, Peak_Time_hist, Delta_Time_hist, Center_Freq_hist, Start_Freq_hist, End_Freq_hist,
Low_Freq_qqplot, High_Freq_qqplot, Peak_Freq_qqplot, Delta_Freq_qqplot, Delta_Time_qqplot, Peak_Time_qqplot, Center_Freq_qqplot, Start_Freq_qqplot, End_Freq_qqplot)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/479263.html