我需要表示一個重要數量的圖形。為了做到這一點,我使用了facet_wrap_paginate函式,但我只列印/繪制了第二頁。
以下是我的資料樣本:
df < -結構(list(oxygen = c(60. 86414, 62.50372, 89. 76055, 61.15914,
61.49936, 61. 90402, 61.60323, 61. 2873, 75.12329, 60. 83503, 63.03796, 60.
61.78298, 70. 16533, 62.60887, 61. 49043, 64.42095, 61. 78358, 62.29302,
62.88122, 60. 47264, 65.92805, 65. 0235, 64.32414, 65. 56869, 64.65729, 65.
66.73502, 67. 01285, 67.47757, 69. 62232, 66.09624, 66. 18106, 64.28226,
64.85658, 67. 46348, 68.93226, 65. 23919, 65.67461, 64. 64727, 64.90544, 64.
68.10878, 70. 00292, 59.54631, 61. 43627, 78.75032, 61. 94263, 82.08963,
62.75281, 61. 93749, 72.86382, 62. 06785, 61.04865, 95. 49206, 69.79339,
66.82354, 61. 53702, 85.51962, 101. 53748, 61.64096, 92.14781, 60.41892, 77. 55303, 75.39007, 62. 15703, 82.38292, 87. 27823, 69.28644, 69.28644,
73.72369, 62. 02667, 61.34973, 61. 61716, 70.61777, 61. 59655, 60.31008,
61.65777, 71. 82138, 61.9823, 79. 38791, 60.31816, 108. 2866, 61.54543,
69.87043, 64. 30304, 65.05726, 68. 69304, 84.0604, 121. 05592, 68.67872,
69.53102, 68. 31013, 64.76675, 122. 22451, 91.29598, 69.43838, 68.73515, 77. 99483, 68.56142, 64. 14964, 73.2695, 69. 67608, 69.01853,
68.5685, 63. 9001, 68.93557, 71. 84125, 72.73052, 69. 17045, 76.28085,
68.41978, 69. 53005, 76.15901, 86. 43705, 72.95997, 64. 0582, 70.29805,
64.10386, 88. 09503, 68.07687, 69. 62147, 67.77802, 125.09757, 91.96934, 97. 26108, 89.16293, 80. 245, 124.97964, 97. 28237, 95.95074,
99.24807, 82. 59685, 89.2217, 77. 50349, 88.54909, 91. 61343, 77.38885,
94.06567, 84. 77561, 80.46941, 92. 28428, 74.25416, 97. 07623),
深度= c(707. 5, 195, 47. 5, 750, 315.5, 506. 5, 660.5, 678,
146, 821. 5, 197, 365, 141. 5, 448, 574.5, 325. 5, 645.5, 236,
446, 872. 5, 315, 729. 5, 786.5, 573. 5, 752, 202。 455, 412,
147, 552. 5, 517, 904, 339. 5, 184, 308.5, 307. 5, 610, 705.
700, 375, 228。 5, 261. 5, 398.5, 168. 5, 360, 136。 5, 504, 299.
187, 473.5, 249. 5, 64. 5, 178.5, 251. 5, 369.5, 95, 66. 5, 599.5,
72, 474。 178, 33. 5, 109, 86. 5, 26.5, 240, 51. 5, 367, 295.
408.5, 244. 5, 106, 314, 304。 5, 69.5, 361. 5, 91.5, 125.5,
11, 281. 5, 101.5, 472. 5, 433, 257。 24, 6, 192. 5, 265, 226, 449, 1.5, 21. 5, 362.5, 238. 5, 33, 246, 477。 5, 46。 109, 315,
275.5, 636, 284. 5, 267, 387, 336. 5, 225. 5, 291。 205, 136, 136,
60.5, 171, 515。 5, 260. 5, 563, 50。 436, 123。 227, 7. 5, 12,
87, 32. 5, 239, 14. 5, 103.5, 90. 5, 120.5, 38. 5, 36.5, 406,
38.5, 143. 5, 371, 87, 54. 5, 234, 53. 5, 260. 5, 123)。 ctd_file = c("BA16007",)
"BA16002",/span> "BA16011"。 "BA16003"。 "BA16004", "BA16006", "BA16001", "BA16001",
"BA16002", "BA16012"。 "BA16003"。 "BA16004", "BA16004"。 "BA16005", "BA16005",
"BA16004", "BA16009"。 "BA16005"。 "BA16012", "BA16004", "BA16006", "BA16006",
"BA16003", "BA16013"。 "BA16014"/span>。 "BA16017", "BA16016", "BA16018", "BA16018",
"BA16016", "BA16014"。 "BA16020"/span>。 "BA16020", "BA16020"。 "BA16016", "BA16016",
"BA16018", "BA16016"。 "BA16018"。 "BA16021", "BA16015", "BA16014", "BA16014",
"BA16013", "BA16015"。 "BA16021"/span>。 "BA16025", "BA16023", "BA16024", "BA16024",
"BA16025", "BA16024"。 "BA16025"。 "BA16025", "BA16025"。 "BA16024", "BA16024",
"BA16025", "BA16023"。 "BA16025"。 "BA16023", "BA16025", "BA16024", "BA16024",
"BA16022", "BA16022"。 "BA16025"。 "BA16024", "BA16024"。 "BA16026", "BA16026",
"BA16035", "BA16030"。 "BA16035"。 "BA16031", "BA16026", "BA16032", "BA16032",
"BA16031", "BA16027"。 "BA16032"。 "BA16035", "BA16028", "BA16031", "BA16031",
"BA16027", "BA16033"。 "BA16032"。 "BA16035", "BA16028", "BA16027", "BA16027",
"BA16032",/span> "BA16034"。 "BA16034"。 "BA16034", "BA16034"。 "BA16034",
"BA16034", "BA16034"。 "BA16034"。 "BA16034", "BA16034"。 "BA16034",
"BA16034",/span> "BA16034"。 "BA16034"。 "BA16034", "BA16034"。 "BA16034",
"BA16034",/span> "BA16034"。 "BA16034"。 "BA16040", "BA16036", "BA16043", "BA16043",
"BA16047",/span> "BA16048"。 "BA16041"。 "BA16049", "BA16036", "BA16042", "BA16042",
"BA16044",/span> "BA16048"。 "BA16045"。 "BA16039", "BA16046", "BA16036", "BA16036",
"BA16048",/span> "BA16044"。 "BA16038"。 "BA16041", "BA16045", "BA16052", "BA16052",
"BA16055", "BA16054"。 "BA16054"。 "BA16053", "BA16053"。 "BA16053", "BA16053",
"BA16055", "BA16055"。 "BA16053"。 "BA16055", "BA16054", "BA16052", "BA16052",
"BA16055", "BA16054"。 "BA16053"。 "BA16054", "BA16055", "BA16052", "BA16052",
"BA16053")。 橫斷面=結構(c(1L。 1L, 1L, 1L。 1L, 1L, 1L,
1L,/span> 1L。 1L, 1L。 1L, 1L。 1L, 1L。 1L, 1L。 1L, 1L。 1L, 1L, 2L, 2L,
2L, 2L。 2L, 2L。 2L, 2L。 2L, 2L。 2L, 2L。 2L, 2L。 2L, 2L。 2L, 2L,
2L, 2L。 2L, 2L。 3L, 3L。 3L, 3L。 3L, 3L。 3L, 3L。 3L, 3L。 3L,
3L, 3L。 3L, 3L。 3L, 3L。 3L, 3L。 3L, 4L。 4L, 4L。 4L, 4L。 4L, 4L,
4L, 4L。 4L, 4L。 4L, 4L。 4L, 4L。 4L, 4L。 4L, 4L。 4L, 4L。 5L,
5L, 5L。 5L, 5L。 5L, 5L。 5L, 5L。 5L, 5L。 5L, 5L。 5L, 5L。 5L,
5L, 5L。 5L, 5L。 6L, 6L。 6L, 6L。 6L, 6L。 6L, 6L。 6L, 6L。 6L,
6L, 6L。 6L, 6L。 6L, 6L。 6L, 6L。 6L, 7L。 7L, 7L。 7L, 7L。 7L, 7L,
7L, 7L。 7L, 7L。 7L, 7L,, 7L, 7L。 7L, 7L。 7L, 7L。 7L), 。 標簽 = c("1",.
"2", "3", "4"。 "5",/span> "6"。 "7")。 class = " factor")。 站=結構(c(7L。
2L, 11L。 3L, 4L。 6L, 1L, 2L。 12L, 3L。 4L, 4L。 5L, 4L。 9L,
5L, 12L。 4L, 6L。 3L, 1L, 2L。 5L, 4L。 6L, 4L。 2L, 8L。 8L, 8L,
8L,/span> 4L。 6L, 4L。 6L, 9L。 3L, 2L。 1L, 3L。 9L, 4L。 2L, 3L。 4L, 4L,
3L, 4L。 4L, 4L。 3L, 4L。 2L, 4L。 2L, 4L。 3L, 1L。 1L, 4L。 3L,
3L, 1L。 9L, 5L。 9L, 6L。 1L,/span> 7L, 6L, 2L。 7L, 9L。 3L, 6L。 2L, 2L,
8L, 7L。 9L, 3L。 2L, 7L。 1L, 1L。 1L, 1L。 1L, 1L。 1L, 1L。 1L, 1L,
1L,/span> 1L。 1L, 1L。 1L, 1L。 1L, 1L。 1L, 1L。 1L, 2L。 1L, 4L。 8L,
9L, 3L。 10L, 1L。 4L, 5L, 9L。 6L, 1L。 7L, 1L。 9L, 5L。 1L, 1L,
3L, 6L。 3L, 6L。 5L, 5L。 4L, 4L。 4L, 6L。 6L, 4L。 6L, 5L。 3L,
6L, 5L。 4L, 5L。 6L, 3L。 4L), 。 標簽 = c("1"。 "2", "3"。 "4",
"5", "6", "7"。 "8", "9", "10"。 "11", "12")。 class = "factor"))。 行。 names = c(NA,
-140L)。 組=結構(list(Transect =結構(1。 7, . 標簽 = c("1", 。
"2", "3", "4"。 "5",/span> "6"。 "7")。 class = " factor"), . rows =結構(list() 。
1:20, 21。 40, 41。 60, 61。 80, 81。 100, 101。 120, 121。 140)。 ptype = integer(0)。 class = c("vctrs_list_of"/span>。
"vctrs_vctr"。 "list")), 行。 names = c(NA。 -7L)。 class = c("tbl_df"。
"tbl", "data.frame"), . drop = TRUE)。 class = c("grouped_df"。
"tbl_df", "tbl", " data. frame"))
這是我使用的代碼:
這是我使用的代碼。
library(dplyr)/span>
library(tidyverse)
library(ggforce)
i <- ceiling()
長度(水平(df$Transect)) / 4) #設定頁數
pdf("multi_page. pdf", width = 16 / 2. 54,高度= 12 / 2。 54)
SdesGG <- df %>% #launch each time or does not work。
group_by(Transect) %>% #mandatory or need to ftify
ggplot(aes(x =氧。 y = depth。 color = Station))
geom_line()
scale_color_brewer(palette = "Paired")
scale_y_reverse()
facet_wrap_paginate(~Transect, ncol = 2, nrow = 2。 頁面= i) #ggforce
dev.off()
我有180 000個觀察值,因此,復制行的數量可能很有趣
lapply(df。 rep, 1000)
uj5u.com熱心網友回復:
用page引數,你只需指定
要繪制的頁面(見
? facet_wrap_paginate)
這就是為什么你用page = i只能得到最后一頁或第二頁。
如果你想要所有的頁面,你必須在頁面上進行回圈:
library(ggplot2
library(ggforce)
i <- ceiling()
長度(水平(df$Transect)) / 4) #設定頁數
pdf("multi_page. pdf", width = 16 / 2. 54,高度= 12 / 2。 54)
lapply(seq(i)。 function(page) {>
SdesGG <- df %>% #launch each time or does not work。
group_by(Transect) %>% #mandatory or need to ftify
ggplot(aes(x =氧, y = depth。 color = Station))
geom_line()
scale_color_brewer(palette = "Paired")
scale_y_reverse()
facet_wrap_paginate(~Transect, ncol = 2, nrow = 2。 頁=頁) #ggforce
})
dev.off()
#> [[1]]/span>

#>
#> [[2]]/span>

轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/330200.html
標籤:
