1

For research purposes, I obtained a NASA data set that has 72 months’ worth of high cloud coverage records for a region in central America. To clean the data I used the included coordinates to create a grid of 576 locations (24x24 grid) and found an average for each of these locations. I then wrote a function that completed this process for each month. As my goal is to visualize the monthly average over the 6 years as well as the yearly average I realized this would be easier if I took all the individual months and combined them into one large data set. This large data set I named (bigboimonth and bigboiyear) contains four variables (Latitude, Longitude, Average, Month). I continued by using gg_maps to generate a map of the region that my data represents by using the extremes of my coordinates. I then generated the yearly averages as geom_points using a facet_grid, which generated a 24x24 grid. I would like to find a way to take the map and use it as a background for my facet grid as the position of each graph on the grid represents the location and displays its averages. So essentially overlay the facet_grid ontop of the map. I have tried this in R by taking the code that generates the grid and adding it to the code that generates the map but receive an error that reads: “Error: Don't know how to add plotyear to a plot.” I am certain that this can be done in R and would be grateful for some advice. I will include code below and dput() a sample of the bigboiyear data. Please let me know if there is any additional information that I can provide and if what I am trying to accomplish is even possible. Thank you in advance for your help!

here is my code

'''
for(t in 1:72){
  mat <- matrix(GridTimeSeries[[t]], nrow = 24, ncol = 24)
  colnames(mat) <- long1
  rownames(mat) <- lat1
  GridTimeSeries2[[t]] <- mat
}

cloudhigh.months <- list()

for(i in 1:12){
  data <- 0
  month <- i
  for(j in seq(month,72,12)){
    data <- data + (matrix(GridTimeSeries2[[j]], nrow = 24, ncol = 24))
  }
  MonthAverage <- data / 6
  colnames(MonthAverage) <- long1
  rownames(MonthAverage) <- lat1
  cloudhigh.months[[i]] <-  MonthAverage
}
names(cloudhigh.months) = c('January', 'Febuary', 'March', 'April', 'May','June','July',
                            'August', 'September', 'October', 'November', 'December')

names(cloudhigh.months) <- month.abb

bigboimonth <- do.call(rbind, lapply(seq_along(cloudhigh.months), function(i) {
  mat <- cloudhigh.months[[i]]
  data.frame(avg = c(mat), longitude = rep(colnames(mat), each = nrow(mat)),
             latitude = rep(rownames(mat), ncol(mat)), month = names(cloudhigh.months)[[i]])
}))
map <- get_stamenmap( bbox = c(left = -113.8, bottom = -21.2, right = -56.2, top = 36.2), zoom = 4, maptype = "terrain-background")
ggmap(map) +
theme_void() +
theme(
plot.title = element_text(colour = "orange"),
panel.border = element_rect(colour = "green", fill=NA, size=2)
)

plot234 <- ggplot(bigboimonth) +
geom_point(aes(month, avg, colour = avg)) +
facet_grid(longitude ~ latitude) + 
scale_color_gradient(low="orange", high="blue") +
theme(axis.text = element_blank(),
strip.text = element_blank(),
axis.ticks = element_blank(),
axis.ticks.length = unit(0, "pt"),
axis.title = element_blank(),
legend.position = c(1.05, 0.5),
legend.justification = c(0, 0.5),
plot.title = element_text(hjust = 0.5, size = 18, face = 'bold'),
panel.background = element_rect(fill = "transparent",colour = NA),
plot.background = element_rect(fill = "transparent",colour = NA))
'''

here is the dput of the frist 576 lines of bigboimonth which will should be the January averages for all of the locations in the grid.

structure(list(avg = c(18, 11, 8, 5.75, 4.33333333333333, 4.25, 
5.83333333333333, 7.75, 9.16666666666667, 9.5, 10.75, 11.0833333333333, 
10, 5.58333333333333, 4.91666666666667, 4, 3.25, 1.16666666666667, 
0.916666666666667, 1.25, 1.58333333333333, 1.58333333333333, 
2.83333333333333, 2.75, 18.0833333333333, 11, 8, 5.33333333333333, 
4.33333333333333, 4.75, 6.08333333333333, 7.75, 8.91666666666667, 
9.91666666666667, 10.9166666666667, 9.83333333333333, 9.08333333333333, 
4.25, 3.66666666666667, 4.16666666666667, 3.83333333333333, 1.25, 
1.08333333333333, 1.25, 1.33333333333333, 1.41666666666667, 2.83333333333333, 
2.91666666666667, 18.0833333333333, 12.1666666666667, 7.16666666666667, 
5.33333333333333, 4.66666666666667, 5.33333333333333, 5.83333333333333, 
8.16666666666667, 8.83333333333333, 10.9166666666667, 11.0833333333333, 
8.25, 8.25, 3.66666666666667, 3.66666666666667, 4.08333333333333, 
3.58333333333333, 1.75, 1, 1.41666666666667, 1.33333333333333, 
1.25, 2.33333333333333, 2.58333333333333, 15.75, 12, 7.91666666666667, 
6.25, 4.66666666666667, 7.33333333333333, 6.75, 8, 7.33333333333333, 
9.66666666666667, 8, 5.58333333333333, 6.75, 2.83333333333333, 
2.58333333333333, 3.41666666666667, 3.58333333333333, 1.66666666666667, 
1.08333333333333, 1.5, 1.33333333333333, 1, 1.75, 2.16666666666667, 
17, 13.3333333333333, 9.83333333333333, 7.5, 7.25, 7.33333333333333, 
8.91666666666667, 7.75, 6, 7.66666666666667, 5.83333333333333, 
4.58333333333333, 6, 3.66666666666667, 2.41666666666667, 3.66666666666667, 
3.83333333333333, 1.83333333333333, 0.916666666666667, 1.16666666666667, 
1.41666666666667, 1.33333333333333, 1.5, 2, 16.5833333333333, 
12.75, 9.58333333333333, 7, 6.91666666666667, 8.83333333333333, 
8.83333333333333, 7.33333333333333, 4.83333333333333, 4.91666666666667, 
3.91666666666667, 4.5, 5.5, 3.91666666666667, 2.33333333333333, 
3.66666666666667, 4.08333333333333, 1.5, 0.583333333333333, 0.833333333333333, 
1, 1.08333333333333, 1.25, 2.83333333333333, 16.0833333333333, 
12, 9, 6.75, 6.83333333333333, 8.08333333333333, 7.66666666666667, 
6.5, 3.75, 3.33333333333333, 3, 4.41666666666667, 5.83333333333333, 
5.08333333333333, 2.91666666666667, 4.08333333333333, 3.75, 2, 
0.75, 0.416666666666667, 0.666666666666667, 0.666666666666667, 
1.41666666666667, 2.33333333333333, 16.0833333333333, 12, 9.33333333333333, 
6.66666666666667, 6.5, 7.25, 6.16666666666667, 5, 2.91666666666667, 
2.08333333333333, 2.41666666666667, 3.25, 5.5, 5.5, 3.75, 4.5, 
4, 2.16666666666667, 0.75, 0.416666666666667, 0.416666666666667, 
0.583333333333333, 0.916666666666667, 1.75, 17, 13.1666666666667, 
9.33333333333333, 8.16666666666667, 6.83333333333333, 6.58333333333333, 
4.58333333333333, 3.58333333333333, 3, 1.75, 1.91666666666667, 
2.25, 5.08333333333333, 5.66666666666667, 3.91666666666667, 3.91666666666667, 
4.5, 2.41666666666667, 1.16666666666667, 0.583333333333333, 0.583333333333333, 
0.333333333333333, 0.583333333333333, 1.16666666666667, 18.5, 
14.75, 10.8333333333333, 10.1666666666667, 7.41666666666667, 
6, 3.91666666666667, 2.91666666666667, 2.91666666666667, 1.75, 
1.16666666666667, 1.41666666666667, 4.58333333333333, 5.66666666666667, 
4.08333333333333, 3.25, 3.91666666666667, 2.83333333333333, 1, 
0.666666666666667, 0.666666666666667, 0.5, 0.5, 1, 18.4166666666667, 
16.5833333333333, 13.0833333333333, 10.1666666666667, 7.91666666666667, 
5.5, 3.91666666666667, 3.16666666666667, 2.91666666666667, 1.25, 
0.666666666666667, 1.41666666666667, 4.83333333333333, 7.41666666666667, 
4.66666666666667, 2.91666666666667, 3.58333333333333, 2.5, 1, 
0.583333333333333, 0.75, 0.5, 0.5, 1, 19.25, 17.9166666666667, 
13.9166666666667, 10.75, 9.25, 6.33333333333333, 4.33333333333333, 
4.41666666666667, 3.33333333333333, 0.833333333333333, 0.916666666666667, 
1.16666666666667, 6.08333333333333, 10.4166666666667, 4.25, 3.41666666666667, 
4.08333333333333, 2.33333333333333, 1.25, 1, 0.916666666666667, 
0.666666666666667, 0.916666666666667, 1.16666666666667, 21, 16.9166666666667, 
13.3333333333333, 12.0833333333333, 9.25, 7.75, 5.16666666666667, 
4.16666666666667, 2.58333333333333, 1.25, 1.91666666666667, 2.33333333333333, 
7.75, 8.75, 4.25, 5, 5.41666666666667, 2.75, 1, 1.5, 0.75, 0.75, 
1.41666666666667, 1.33333333333333, 21, 16.9166666666667, 12.9166666666667, 
12.1666666666667, 9.58333333333333, 7.5, 4.75, 3.16666666666667, 
1.83333333333333, 1.25, 1.66666666666667, 3.91666666666667, 7.91666666666667, 
10.6666666666667, 9.58333333333333, 10.5, 10.5, 6.41666666666667, 
2.66666666666667, 3.5, 1.5, 1.5, 1.33333333333333, 1, 19.5833333333333, 
16.0833333333333, 14, 11.5833333333333, 9.5, 5.75, 3.83333333333333, 
2, 1.08333333333333, 0.75, 1, 4.08333333333333, 11.25, 17.1666666666667, 
19.6666666666667, 21.5833333333333, 23.25, 18.4166666666667, 
10, 20.0833333333333, 4.25, 2.08333333333333, 1.16666666666667, 
0.75, 16.3333333333333, 15.3333333333333, 14, 11.9166666666667, 
9, 5.75, 3.41666666666667, 1.41666666666667, 1, 0.666666666666667, 
0.833333333333333, 4, 14.9166666666667, 17.0833333333333, 19.6666666666667, 
24.25, 30.25, 31.0833333333333, 36.3333333333333, 45.1666666666667, 
23.9166666666667, 3.75, 1.75, 0.666666666666667, 15.75, 15.25, 
15.0833333333333, 12.75, 8.33333333333333, 5.75, 2.41666666666667, 
1.25, 0.583333333333333, 0.5, 0.916666666666667, 2.91666666666667, 
8.33333333333333, 9.5, 13.25, 25.0833333333333, 33.5, 34.4166666666667, 
39.3333333333333, 43, 44.5, 14.4166666666667, 3.5, 0.916666666666667, 
15.8333333333333, 15.6666666666667, 15.4166666666667, 12.5, 8, 
4.91666666666667, 2.16666666666667, 0.833333333333333, 0.5, 0.5, 
0.666666666666667, 2.33333333333333, 3.41666666666667, 6.91666666666667, 
17.4166666666667, 30.5833333333333, 36.9166666666667, 38.25, 
39.5833333333333, 37.1666666666667, 47.1666666666667, 33, 16.8333333333333, 
1.75, 15.8333333333333, 16.6666666666667, 16.1666666666667, 12.5, 
7.33333333333333, 4.66666666666667, 2, 0.916666666666667, 0.416666666666667, 
0.583333333333333, 0.583333333333333, 1.08333333333333, 2.16666666666667, 
12.0833333333333, 26, 34.3333333333333, 39.75, 41.8333333333333, 
40.5, 38.3333333333333, 36.9166666666667, 41.1666666666667, 34.6666666666667, 
14.4166666666667, 17.8333333333333, 16.6666666666667, 15.5833333333333, 
11.5, 7.25, 4.5, 2.33333333333333, 0.916666666666667, 0.25, 0.5, 
0.5, 0.75, 3.5, 15.4166666666667, 27.4166666666667, 33, 39.9166666666667, 
44.5, 43.5833333333333, 40.3333333333333, 35, 37.4166666666667, 
34.6666666666667, 29.8333333333333, 19.3333333333333, 18.25, 
15.6666666666667, 11.8333333333333, 7.08333333333333, 4.41666666666667, 
2.66666666666667, 1.33333333333333, 0.25, 0.5, 0.416666666666667, 
0.75, 4.66666666666667, 14.6666666666667, 21.0833333333333, 29.9166666666667, 
38.8333333333333, 43, 43.9166666666667, 44.5, 37.6666666666667, 
31.25, 32.4166666666667, 21.8333333333333, 21.0833333333333, 
18.75, 15.4166666666667, 11.6666666666667, 6.08333333333333, 
4.33333333333333, 2.41666666666667, 1.58333333333333, 0.75, 0.916666666666667, 
1.83333333333333, 2.83333333333333, 7.08333333333333, 12.8333333333333, 
18.6666666666667, 31.0833333333333, 38.9166666666667, 44.75, 
47, 45.1666666666667, 42.6666666666667, 30.4166666666667, 21.5833333333333, 
19.25, 22.0833333333333, 18.5833333333333, 15.4166666666667, 
9.66666666666667, 6.08333333333333, 4, 1.83333333333333, 1.16666666666667, 
0.916666666666667, 1.25, 1.83333333333333, 5.41666666666667, 
8.83333333333333, 11.0833333333333, 18.9166666666667, 30.8333333333333, 
38.25, 44.3333333333333, 45.75, 45.1666666666667, 44.0833333333333, 
36.8333333333333, 25.8333333333333, 24.4166666666667, 22.0833333333333, 
18, 13.5833333333333, 7.83333333333333, 5.58333333333333, 4.25, 
2.16666666666667, 1.75, 1.25, 1.5, 2.16666666666667, 5.75, 9.58333333333333, 
16.3333333333333, 22.5, 32.4166666666667, 38, 43.4166666666667, 
46, 46.4166666666667, 43.8333333333333, 41.1666666666667, 31.8333333333333, 
31.9166666666667), longitude = structure(c(6L, 6L, 6L, 6L, 6L, 
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 
6L, 6L, 6L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 4L, 4L, 4L, 4L, 4L, 
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
4L, 4L, 4L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 24L, 24L, 24L, 24L, 
24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 
24L, 24L, 24L, 24L, 24L, 24L, 24L, 23L, 23L, 23L, 23L, 23L, 23L, 
23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 
23L, 23L, 23L, 23L, 23L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 
22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 
22L, 22L, 22L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 
21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 
21L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 19L, 
19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 
19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 18L, 18L, 18L, 
18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 
18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 17L, 17L, 17L, 17L, 17L, 
17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 
17L, 17L, 17L, 17L, 17L, 17L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 
16L, 16L, 16L, 16L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 
15L, 15L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 12L, 12L, 
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 11L, 11L, 11L, 11L, 
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 
11L, 11L, 11L, 11L, 11L, 11L, 11L, 10L, 10L, 10L, 10L, 10L, 10L, 
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 
10L, 10L, 10L, 10L, 10L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 8L, 
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 
8L, 8L, 8L, 8L, 8L, 8L, 8L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L), .Label = c("101.2W", 
"103.8W", "106.2W", "108.8W", "111.2W", "113.8W", "56.2W", "58.8W", 
"61.2W", "63.8W", "66.2W", "68.8W", "71.2W", "73.8W", "76.2W", 
"78.8W", "81.2W", "83.8W", "86.2W", "88.8W", "91.2W", "93.8W", 
"96.2W", "98.8W"), class = "factor"), latitude = structure(c(20L, 
19L, 18L, 15L, 14L, 13L, 11L, 9L, 7L, 5L, 3L, 23L, 21L, 16L, 
1L, 2L, 17L, 22L, 24L, 4L, 6L, 8L, 10L, 12L, 20L, 19L, 18L, 15L, 
14L, 13L, 11L, 9L, 7L, 5L, 3L, 23L, 21L, 16L, 1L, 2L, 17L, 22L, 
24L, 4L, 6L, 8L, 10L, 12L, 20L, 19L, 18L, 15L, 14L, 13L, 11L, 
9L, 7L, 5L, 3L, 23L, 21L, 16L, 1L, 2L, 17L, 22L, 24L, 4L, 6L, 
8L, 10L, 12L, 20L, 19L, 18L, 15L, 14L, 13L, 11L, 9L, 7L, 5L, 
3L, 23L, 21L, 16L, 1L, 2L, 17L, 22L, 24L, 4L, 6L, 8L, 10L, 12L, 
20L, 19L, 18L, 15L, 14L, 13L, 11L, 9L, 7L, 5L, 3L, 23L, 21L, 
16L, 1L, 2L, 17L, 22L, 24L, 4L, 6L, 8L, 10L, 12L, 20L, 19L, 18L, 
15L, 14L, 13L, 11L, 9L, 7L, 5L, 3L, 23L, 21L, 16L, 1L, 2L, 17L, 
22L, 24L, 4L, 6L, 8L, 10L, 12L, 20L, 19L, 18L, 15L, 14L, 13L, 
11L, 9L, 7L, 5L, 3L, 23L, 21L, 16L, 1L, 2L, 17L, 22L, 24L, 4L, 
6L, 8L, 10L, 12L, 20L, 19L, 18L, 15L, 14L, 13L, 11L, 9L, 7L, 
5L, 3L, 23L, 21L, 16L, 1L, 2L, 17L, 22L, 24L, 4L, 6L, 8L, 10L, 
12L, 20L, 19L, 18L, 15L, 14L, 13L, 11L, 9L, 7L, 5L, 3L, 23L, 
21L, 16L, 1L, 2L, 17L, 22L, 24L, 4L, 6L, 8L, 10L, 12L, 20L, 19L, 
18L, 15L, 14L, 13L, 11L, 9L, 7L, 5L, 3L, 23L, 21L, 16L, 1L, 2L, 
17L, 22L, 24L, 4L, 6L, 8L, 10L, 12L, 20L, 19L, 18L, 15L, 14L, 
13L, 11L, 9L, 7L, 5L, 3L, 23L, 21L, 16L, 1L, 2L, 17L, 22L, 24L, 
4L, 6L, 8L, 10L, 12L, 20L, 19L, 18L, 15L, 14L, 13L, 11L, 9L, 
7L, 5L, 3L, 23L, 21L, 16L, 1L, 2L, 17L, 22L, 24L, 4L, 6L, 8L, 
10L, 12L, 20L, 19L, 18L, 15L, 14L, 13L, 11L, 9L, 7L, 5L, 3L, 
23L, 21L, 16L, 1L, 2L, 17L, 22L, 24L, 4L, 6L, 8L, 10L, 12L, 20L, 
19L, 18L, 15L, 14L, 13L, 11L, 9L, 7L, 5L, 3L, 23L, 21L, 16L, 
1L, 2L, 17L, 22L, 24L, 4L, 6L, 8L, 10L, 12L, 20L, 19L, 18L, 15L, 
14L, 13L, 11L, 9L, 7L, 5L, 3L, 23L, 21L, 16L, 1L, 2L, 17L, 22L, 
24L, 4L, 6L, 8L, 10L, 12L, 20L, 19L, 18L, 15L, 14L, 13L, 11L, 
9L, 7L, 5L, 3L, 23L, 21L, 16L, 1L, 2L, 17L, 22L, 24L, 4L, 6L, 
8L, 10L, 12L, 20L, 19L, 18L, 15L, 14L, 13L, 11L, 9L, 7L, 5L, 
3L, 23L, 21L, 16L, 1L, 2L, 17L, 22L, 24L, 4L, 6L, 8L, 10L, 12L, 
20L, 19L, 18L, 15L, 14L, 13L, 11L, 9L, 7L, 5L, 3L, 23L, 21L, 
16L, 1L, 2L, 17L, 22L, 24L, 4L, 6L, 8L, 10L, 12L, 20L, 19L, 18L, 
15L, 14L, 13L, 11L, 9L, 7L, 5L, 3L, 23L, 21L, 16L, 1L, 2L, 17L, 
22L, 24L, 4L, 6L, 8L, 10L, 12L, 20L, 19L, 18L, 15L, 14L, 13L, 
11L, 9L, 7L, 5L, 3L, 23L, 21L, 16L, 1L, 2L, 17L, 22L, 24L, 4L, 
6L, 8L, 10L, 12L, 20L, 19L, 18L, 15L, 14L, 13L, 11L, 9L, 7L, 
5L, 3L, 23L, 21L, 16L, 1L, 2L, 17L, 22L, 24L, 4L, 6L, 8L, 10L, 
12L, 20L, 19L, 18L, 15L, 14L, 13L, 11L, 9L, 7L, 5L, 3L, 23L, 
21L, 16L, 1L, 2L, 17L, 22L, 24L, 4L, 6L, 8L, 10L, 12L, 20L, 19L, 
18L, 15L, 14L, 13L, 11L, 9L, 7L, 5L, 3L, 23L, 21L, 16L, 1L, 2L, 
17L, 22L, 24L, 4L, 6L, 8L, 10L, 12L, 20L, 19L, 18L, 15L, 14L, 
13L, 11L, 9L, 7L, 5L, 3L, 23L, 21L, 16L, 1L, 2L, 17L, 22L, 24L, 
4L, 6L, 8L, 10L, 12L), .Label = c("1.2N", "1.2S", "11.2N", "11.2S", 
"13.8N", "13.8S", "16.2N", "16.2S", "18.8N", "18.8S", "21.2N", 
"21.2S", "23.8N", "26.2N", "28.8N", "3.8N", "3.8S", "31.2N", 
"33.8N", "36.2N", "6.2N", "6.2S", "8.8N", "8.8S"), class = "factor"), 
    month = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,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), row.names = c(NA, 576L
), class = "data.frame")
Matt
  • 7,255
  • 2
  • 12
  • 34
  • Could you `dput` a small subset of the `bigboimonth` data? – Edward Mar 08 '20 at 02:39
  • I'm afraid I don't know how to use dput but I will include the head(bigboimonth) in the post. hopefully, this is helpful, otherwise, I'll try to figure out how to dput it – Frederic Klostermyer Mar 08 '20 at 03:31
  • [Here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610) is some excellent information on how and when to use `dput`. By providing a good minimal reproducible example you can help others to help you :) – dario Mar 08 '20 at 09:29
  • Last example on this page: https://heima.hafro.is/~einarhj/spatialr/pre_ggplot2.html may help you. – einar Mar 08 '20 at 15:01
  • I looked at the example and tried to use it in my code but am still coming up with an error to get it to run. – Frederic Klostermyer Mar 10 '20 at 01:31

1 Answers1

0

this is da way

cloudhigh.years <- list()

for(i in 0:5){
  data <- 0
  year <- i
  for(j in seq((year*12)+1,(12*year)+12)){
    data <- data + (matrix(GridTimeSeries2[[j]], nrow = 24, ncol = 24))
  }
  YearAverage <- data / 12
  colnames(YearAverage) <- long1
  rownames(YearAverage) <- lat1
  cloudhigh.years[[i+1]] <-  YearAverage
}

names(cloudhigh.years) <- c("year1", "year2", "year3", "year4", "year5", "year6")

bigboiyear <- do.call(rbind, lapply(seq_along(cloudhigh.years), function(i) {
  mat <- cloudhigh.years[[i]]
  data.frame(avg = c(mat), longitude = rep(colnames(mat), each = nrow(mat)),
             latitude = rep(rownames(mat), ncol(mat)), year = names(cloudhigh.years)[[i]])
}))



plotyear <- ggplot(bigboiyear) +
  geom_point(aes(year, avg, colour = avg)) +
  facet_grid(longitude ~ latitude) +
  scale_color_gradient(low="orange", high="blue") +
  theme(axis.text = element_blank(),
        strip.text = element_blank(),
        axis.ticks = element_blank(),
        axis.ticks.length = unit(0, "pt"),
        axis.title = element_blank(),
        legend.position = c(1.05, 0.5),
        legend.justification = c(0, 0.5),
        plot.title = element_text(hjust = 0.5, size = 18, face = 'bold'),
        panel.background = element_rect(fill = "transparent",colour = NA),
        plot.background = element_rect(fill = "transparent",colour = NA))


plotyear

plotyear <- ggplot(bigboiyear) +
  geom_point(aes(year, avg, colour = avg),size =.75) +
  facet_grid(longitude ~ latitude) +
  scale_color_gradient(low="orange", high="blue") +
  theme(axis.text = element_blank(),
        strip.text = element_blank(),
        axis.ticks = element_blank(),
        axis.ticks.length = unit(0, "pt"),
        axis.title = element_blank(),
        legend.position = c(1.05, 0.5),
        legend.justification = c(0, 0.5),
        plot.title = element_text(hjust = 0.5, size = 18, face = 'bold'),
        panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.border = element_rect(size=.5, fill=NA, colour = 'black'),
        panel.background = element_rect(fill = "transparent",colour = NA),
        plot.background = element_rect(fill = "transparent",colour = NA))


plotyear

map <- get_stamenmap( bbox = c(left = -113.8, bottom = -21.2, right = -56.2, top = 36.2), zoom = 4, maptype = "terrain-background")
p2<-ggmap(map) +
  theme(
    plot.title = element_text(colour = "orange"),
    panel.border = element_rect(colour = "green", fill=NA, size=2),
    axis.text.x = element_blank(),
    axis.text.y = element_blank(),
    axis.ticks = element_blank()
  ) +
  inset(ggplotGrob(plotyear), xmin = Inf, xmax = -Inf, ymin = Inf, ymax = -Inf)
p2 + ggtitle("Average Yearly High Cloud Coverage for Central America")+ xlab("Years(1995-2000)")+ylab("Average High Cloud Coverage Level")+
  theme(plot.title = element_text(hjust = 0.5, size = 15, face = 'bold'))

essentially the part I was getting hung up on was at the inset(ggplotGorb()) statement. By setting infinite bounds and already having created the facet grid plot above, it allowed me to overlay the facet grid of plots over the regional map based on their latitude and longitude. The remainder of the code is primarily just ggplot theme work and making the legend and other parts of the visual look more aesthetically pleasing.

  • While your answer may solve the question, [including an explanation](https://meta.stackexchange.com/q/114762) of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please edit your answer to add explanations and give an indication of what limitations and assumptions apply. - [From Review](https://stackoverflow.com/review/late-answers/28219950) – Adam Marshall Feb 01 '21 at 18:41