将标签和标题添加到从 lapply 函数派生的图中
Add labels and title to a plot derived from an lapply function
我不知道如何为整个图添加标题和轴标签。 (不仅仅是每个面板上的轴标签)
structure(list(Date = structure(c(16709, 15126, 14883, 16587,
15095, 15492, 14549, 17410, 16314, 17348, 14761, 14457, 16375,
17014, 15857, 17836, 15826, 15522, 15918, 15857), class = "Date"),
Commonname = c("Black Sea Bass", "Pinfish", "Silver Perch",
"Black Sea Bass", "Silver Perch", "Pinfish", "Pinfish", "Pigfish",
"Pinfish", "Black Sea Bass", "Silver Perch", "Pinfish", "Black Sea Bass",
"Pigfish", "Black Sea Bass", "Pinfish", "Black Sea Bass",
"Pigfish", "Black Sea Bass", "Silver Perch"), CPUE = c(1.07628582778677,
7.86657009496217, 1.85135216165977, 0.348590691952807, 0.397594400562561,
4.49617260026057, 9.8560683819882, 2.52182932296262, 4.66061566304416,
1.85247646459195, 1.09432152065719, 12.0038255707299, 0.145989032254548,
1.86725301741492, 1.07356515883229, 11.5172014403701, 0.296643539261688,
2.70394855189782, 1.14838123183663, 0.871334772441085), Discharge = c(3.02423424,
0.232938467873684, 2.141316416, 1.31224770666667, 1.03639488,
14.38635024, 1.2352637664, 8.27794453333333, 7.04587330461538,
6.47180464, 5.84804846222222, 2.37460535832896, 1.68201792,
19.73397792, 3.56857026461538, 4.89821025684211, 5.41174500571429,
33.25524992, 47.1935879314286, 3.88199730666667)), row.names = c(NA,
-20L), class = c("tbl_df", "tbl", "data.frame"))
df.split <- split(df, df$Commonname, drop = TRUE)
par(mfrow=c(2,2))
lapply(seq_along(df.split), function(x) ccf(df.split[[x]]$CPUE,df.split[[x]]$Discharge, lag.max = 5,
ylab = "", xlab = "", main= names(df.split)[x]))
我无法将它添加到函数中,或者它适用于所有面板。
我刚刚添加了 title()
功能;
df.split <- split(df, df$Commonname, drop = TRUE)
par(mfrow=c(2,2))
lapply(seq_along(df.split), function(x) ccf(df.split[[x]]$CPUE,df.split[[x]]$Discharge, lag.max = 5,
ylab = "", xlab = "", main= names(df.split)[x]))
title("This is a main title", line = -1, outer = TRUE,xlab = 'This is x axis',ylab = 'This is y axis')
在前面答案的帮助下,我使用这段代码将它带到了我需要实际绘图和数据的地方。
d.select.ccf <- BD %>%
group_by(Zone, Date, Commonname) %>%
filter(Zone == "D") %>%
summarise(Number = sum(Number), CPUE = mean((CPUE)), Discharge = mean (Discharge)) %>%
ungroup()
d.spp <- subset(d.select.ccf, Commonname == "Pigfish" | Commonname == "Pinfish"
| Commonname == "Silver Perch"
| Commonname == 'Spottail Pinfish' | Commonname == "Dusky Pipefish"
| Commonname == "Black Sea Bass"
| Commonname == "Pink Shrimp" | Commonname == "Scallops"
| Commonname == 'Grass Porgy' | Commonname == 'Lane Snapper'
| Commonname == 'White Grunt'| Commonname == "Spotted Seatrout")
d.split <- split(d.spp, d.spp$Commonname, drop = TRUE)
par(mfrow=c(4,3),omi=c(0.1,0.1,0.1,0.2), mai=c(0.55,0.6,0.7,0.5))
d.ccf.plot <- lapply(seq_along(d.split), function(x) ccf(d.split[[x]]$CPUE,d.split[[x]]$Discharge, lag.max = 5,
xlab = "", ylab = "", sub = "", main= names(d.split)[x]))
title("Steinhatchee Lag Correlations", sub = " ", line = -1, outer = TRUE,
xlab = 'Lag (months)',ylab = 'Correlation Coefficient', cex.main = 1.5, cex.lab = 1.5)
当然,您需要完整的数据集才能获得此图像,该图像对于 post 来说太大了。但我希望这种替代方法可以帮助某人。
我不知道如何为整个图添加标题和轴标签。 (不仅仅是每个面板上的轴标签)
structure(list(Date = structure(c(16709, 15126, 14883, 16587,
15095, 15492, 14549, 17410, 16314, 17348, 14761, 14457, 16375,
17014, 15857, 17836, 15826, 15522, 15918, 15857), class = "Date"),
Commonname = c("Black Sea Bass", "Pinfish", "Silver Perch",
"Black Sea Bass", "Silver Perch", "Pinfish", "Pinfish", "Pigfish",
"Pinfish", "Black Sea Bass", "Silver Perch", "Pinfish", "Black Sea Bass",
"Pigfish", "Black Sea Bass", "Pinfish", "Black Sea Bass",
"Pigfish", "Black Sea Bass", "Silver Perch"), CPUE = c(1.07628582778677,
7.86657009496217, 1.85135216165977, 0.348590691952807, 0.397594400562561,
4.49617260026057, 9.8560683819882, 2.52182932296262, 4.66061566304416,
1.85247646459195, 1.09432152065719, 12.0038255707299, 0.145989032254548,
1.86725301741492, 1.07356515883229, 11.5172014403701, 0.296643539261688,
2.70394855189782, 1.14838123183663, 0.871334772441085), Discharge = c(3.02423424,
0.232938467873684, 2.141316416, 1.31224770666667, 1.03639488,
14.38635024, 1.2352637664, 8.27794453333333, 7.04587330461538,
6.47180464, 5.84804846222222, 2.37460535832896, 1.68201792,
19.73397792, 3.56857026461538, 4.89821025684211, 5.41174500571429,
33.25524992, 47.1935879314286, 3.88199730666667)), row.names = c(NA,
-20L), class = c("tbl_df", "tbl", "data.frame"))
df.split <- split(df, df$Commonname, drop = TRUE)
par(mfrow=c(2,2))
lapply(seq_along(df.split), function(x) ccf(df.split[[x]]$CPUE,df.split[[x]]$Discharge, lag.max = 5,
ylab = "", xlab = "", main= names(df.split)[x]))
我无法将它添加到函数中,或者它适用于所有面板。
我刚刚添加了 title()
功能;
df.split <- split(df, df$Commonname, drop = TRUE)
par(mfrow=c(2,2))
lapply(seq_along(df.split), function(x) ccf(df.split[[x]]$CPUE,df.split[[x]]$Discharge, lag.max = 5,
ylab = "", xlab = "", main= names(df.split)[x]))
title("This is a main title", line = -1, outer = TRUE,xlab = 'This is x axis',ylab = 'This is y axis')
在前面答案的帮助下,我使用这段代码将它带到了我需要实际绘图和数据的地方。
d.select.ccf <- BD %>%
group_by(Zone, Date, Commonname) %>%
filter(Zone == "D") %>%
summarise(Number = sum(Number), CPUE = mean((CPUE)), Discharge = mean (Discharge)) %>%
ungroup()
d.spp <- subset(d.select.ccf, Commonname == "Pigfish" | Commonname == "Pinfish"
| Commonname == "Silver Perch"
| Commonname == 'Spottail Pinfish' | Commonname == "Dusky Pipefish"
| Commonname == "Black Sea Bass"
| Commonname == "Pink Shrimp" | Commonname == "Scallops"
| Commonname == 'Grass Porgy' | Commonname == 'Lane Snapper'
| Commonname == 'White Grunt'| Commonname == "Spotted Seatrout")
d.split <- split(d.spp, d.spp$Commonname, drop = TRUE)
par(mfrow=c(4,3),omi=c(0.1,0.1,0.1,0.2), mai=c(0.55,0.6,0.7,0.5))
d.ccf.plot <- lapply(seq_along(d.split), function(x) ccf(d.split[[x]]$CPUE,d.split[[x]]$Discharge, lag.max = 5,
xlab = "", ylab = "", sub = "", main= names(d.split)[x]))
title("Steinhatchee Lag Correlations", sub = " ", line = -1, outer = TRUE,
xlab = 'Lag (months)',ylab = 'Correlation Coefficient', cex.main = 1.5, cex.lab = 1.5)
当然,您需要完整的数据集才能获得此图像,该图像对于 post 来说太大了。但我希望这种替代方法可以帮助某人。