如何解决如何缩放ggplot2中的数据并将额外的图添加到现有图
嗨,我沿着样条线有两个相对丰度数据图。由于一个样带有一个额外的物种,因此ggplot2会自动将图形绘制为相同大小。我想缩放数据,以使两个图上的列高均相等。我还想将高程数据再次添加到两个图的顶部,缩放到相同的y轴。在代码中,“深度”被用作“距离”的替代,因为这是tidypaleo所喜欢的。
有人可以帮忙吗?
st1<-read.csv("st11raw.csv",header=TRUE)
library(tidypaleo)
library(tidyverse)
theme_set(theme_bw(8))
library(grid)
st1<-pivot_longer(st1,-1,names_to="species",values_to = "rel_abund")
P1<-ggplot(st1,aes(x = Depth,y = rel_abund,fill=species)) +
geom_col() +
facet_abundance(vars(species)) +
labs(x = "distance (m)",y = "Relative abundance")
P1
st2<-read.csv("st2raw.csv",header=TRUE)
st2$Sample=NULL
st2$Elevation.GDA.2020=NULL
st2$A.agglutinans=NULL
st2$Total=NULL
st2$Textularia=NULL
st2$S.lobata=NULL
st2$A.beccarri=NULL
st2$P.ipohalina=NULL
st2$T.salsa=NULL
st2<-pivot_longer(st2,values_to = "rel_abund")
P2<- ggplot(st2,y = "Relative abundance")
P2
library(gridExtra)
grid.arrange(P1,P2,nrow = 2)
以下是丰度数据的代码:
structure(list(Depth = c(24L,24L,24L),species =
c("T.salsa","H.wilberti","T.irregularis","E.macrescens","T.inflata","M.fusca"
),rel_abund = c(10.44226044,29.97542998,2.088452088,4.422604423,50,2.702702703)),row.names = c(NA,-6L),class = c("tbl_df","tbl","data.frame"))
structure(list(Depth = c(0L,0L,20L),species = c("H.wilberti","J.macrescens","M.fusca","H.wilberti"
),rel_abund = c(0,0.716845878)),"data.frame"))
以下是高度数据的代码:
structure(list(Depth = c(24L,26L,30L,32L,38L,48L),Elevation =
c(0.937,0.85,0.915,0.868,0.836,0.81)),6L),class =
"data.frame")
dput(head(st2$Elevation.GDA.2020))
c(0.765,0.786,0.737,0.69,0.678,0.634)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。