如何在errorbar行中指定特定csv

如何在errorbar行中指定特定csv,r,ggplot2,R,Ggplot2,我正试图用三种不同的CSV绘制一个图。其中两列相同,即年份、GMSL和GMSLerror 在Frederikse文件中,列为Year、GMSL、GMSLerrorlow和gmslerrorrup。我如何告诉R使用GMSLerrorlow和gmslerrorrup列绘制Frederikse错误?我尝试了以下方法,但没有成功。谢谢 p1<-files <- c("Frederikse.csv", "ChurchandWhite.csv","

我正试图用三种不同的CSV绘制一个图。其中两列相同,即年份、GMSL和GMSLerror

在Frederikse文件中,列为Year、GMSL、GMSLerrorlow和gmslerrorrup。我如何告诉R使用GMSLerrorlow和gmslerrorrup列绘制Frederikse错误?我尝试了以下方法,但没有成功。谢谢

p1<-files <- c("Frederikse.csv", "ChurchandWhite.csv","Hay.csv")
map_dfr(files, ~ read_csv(.x) %>% 
          mutate(Author = .x)) %>%
  ggplot(aes(x = Time, y = GMSL, color = Author,fill=Author)) +
  geom_line(size=0.6)+
  theme_bw(12)+
  theme(panel.grid.major = element_blank())+
  theme(panel.grid.minor = element_blank())+
  labs(x = "Year", y = "GMSL (mm)",color="Author")+
  geom_errorbar(aes(ymin=GMSL-GMSLerror, ymax =GMSL+GMSLerror,alpha=Author))+
  geom_errorbar("Frederikse.csv",(aes(ymin=GMSL-GMSLerrorlow, ymax =GMSL+GMSLerrorup,alpha=Author)))
  scale_alpha_manual(values = c(0.3, 0.3, 0.8))+
  scale_colour_manual(values=c("#BAB3F0","#1D3E72","#201641"))
  
p1


structure(list(Year = 1900:1905, GMSLerrorlow = c(-203.5572666, 
-201.0185091, -212.0740442, -202.6975639, -200.1670151, -192.1312551
), GMSL = c(-173.2614421, -168.8016753, -180.389967, -170.2678322, 
-168.7200709, -160.9814287), GMSLerrorup = c(-141.002807, -135.8976091, 
-148.213824, -138.9305182, -137.4501224, -130.3514508)), row.names = c(NA, 
6L), class = "data.frame")

structure(list(Time = 1900:1905, GMSL = c(-131.15, -130.5, -129.77, 
-128.85, -128.1, -127.56), GMSLerror = c(25.32, 25.17, 25.01, 
24.86, 24.7, 24.55)), row.names = c(NA, 6L), class = "data.frame")


structure(list(Time = c(1880.0417, 1880.125, 1880.2083, 1880.2917, 
1880.375, 1880.4583), GMSL = c(-183, -171.1, -164.3, -158.2, 
-158.7, -159.6), GMSLerror = c(24.2, 24.2, 24.2, 24.2, 24.2, 
24.2)), row.names = c(NA, 6L), class = "data.frame")````
p1%
ggplot(aes(x=时间,y=GMSL,颜色=作者,填充=作者))+
几何尺寸线(尺寸=0.6)+
主题(12)+
主题(panel.grid.major=element\u blank())+
主题(panel.grid.minor=element\u blank())+
实验室(x=“年”,y=“GMSL(mm)”,color=“作者”)+
几何误差条(aes(ymin=GMSL GMSLerror,ymax=GMSL+GMSLerror,alpha=Author))+
geom_errorbar(“Frederikse.csv”,(aes(ymin=GMSL-GMSLerrorlow,ymax=GMSL+gmslerrorrup,alpha=Author)))
比例α手册(值=c(0.3,0.3,0.8))+
刻度颜色手册(数值=c(“#BAB3F0”、“#1D3E72”、“#201641”))
p1
结构(列表)(年份=1900:1905,GMSLerrorlow=c(-203.5572666,
-201.0185091, -212.0740442, -202.6975639, -200.1670151, -192.1312551
),GMSL=c(-173.2614421,-168.8016753,-180.389967,-170.2678322,
-168.7200709,-160.9814287),gmslerrorrup=c(-141.002807,-135.8976091,
-148.213824,-138.9305182,-137.4501224,-130.3514508),row.names=c(NA,
6L),class=“数据帧”)
结构(列表)(时间=1900:1905,GMSL=c(-131.15,-130.5,-129.77,
-128.85,-128.1,-127.56),GMSLerror=c(25.32,25.17,25.01,
24.86,24.7,24.55),row.names=c(NA,6L),class=“data.frame”)
结构(列表)(时间=c(1880.04171880.1251880.20831880.2917,
GMSL=c(-183,-171.1,-164.3,-158.2,
-158.7,-159.6),GMSLerror=c(24.2,24.2,24.2,24.2,24.2,24.2,
24.2),row.names=c(NA,6L),class=“data.frame”)````

您可以使用
mutate
为所有数据集创建
GMSLerrorlow

p1<-files <- c("Frederikse.csv", "ChurchandWhite.csv","Hay.csv")

set_names(files) %>% # give names - can use str_remove to drop `.csv` from names

map_dfr( ~ read_csv(.x), .id = "Author") %>% #use .id argument
mutate(
   GMSLerrorlow = if_else(Author != "Frederikse.csv", GMSLerror, GMSLerrorlow),
   GMSLerrorup = if_else(Author != "Frederikse.csv", GMSLerror, GMSLerrorup)
) %>%

  ggplot(aes(x = Time, y = GMSL, color = Author,fill=Author)) +
  geom_line(size=0.6)+
  theme_bw(12)+
  theme(panel.grid.major = element_blank())+
  theme(panel.grid.minor = element_blank())+
  labs(x = "Year", y = "GMSL (mm)",color="Author")+
  geom_errorbar(aes(ymin=GMSL-GMSLerrorlow, ymax =GMSL+GMSLerrorup,alpha=Author))+
  scale_alpha_manual(values = c(0.3, 0.3, 0.8))+
  scale_colour_manual(values=c("#BAB3F0","#1D3E72","#201641"))
p1%#使用.id参数
变异(
GMSLerrorlow=if_else(作者!=“Frederikse.csv”,GMSLerror,GMSLerrorlow),
GMSLerrorup=if_else(作者!=“Frederikse.csv”,GMSLerror,GMSLerrorup)
) %>%
ggplot(aes(x=时间,y=GMSL,颜色=作者,填充=作者))+
几何尺寸线(尺寸=0.6)+
主题(12)+
主题(panel.grid.major=element\u blank())+
主题(panel.grid.minor=element\u blank())+
实验室(x=“年”,y=“GMSL(mm)”,color=“作者”)+
geom_errorbar(aes(ymin=GMSL GMSLerrorlow,ymax=GMSL+GMSLerrorrup,alpha=Author))+
比例α手册(值=c(0.3,0.3,0.8))+
刻度颜色手册(数值=c(“#BAB3F0”、“#1D3E72”、“#201641”))