Hello everyone.
I'm beginner in RSTUDIO and have to create figures from different days but in a loop system.
Actually, the purpouse of the work is for one full month, this code example is just for 5 days but the idea is the same.
My problem is, reviewing different ways to create a loop for export different plots, I couldn't find a good example because in each figure I have to:
- Create a figure with a specific title like "IMAGE DAY xx/xx/xxxx SENSOR xxxxx"
- Each output has to have a different name (for not overwrite each one"
3.Legend and axis are the same for all figures.
My question is if I can get a suggestion for write the code below but in "loop". Following other examples, I create one text files that contain all the output names (called "listfigures.txt")
But I stuck here, don't have more lights about this process.
Thanks to all for your replies.
Christian.
#Directory work
library("rstudioapi")
library(png)
library(tidyverse)
library(lubridate)
library(reprex)
data("coastlineWorld")
#Read the read file contain all filenames to use for export purpose, currentlly unused.
my_list <- read.delim("listfigures.txt")
### List file stored in "listfigure.txt"
#2019-02-01_Modis_2019.jpg
#2019-02-02_Modis_2019.jpg
#2019-02-03_Modis_2019.jpg
#2019-02-04_Modis_2019.jpg
#2019-02-05_Modis_2019.jpg
#Common objects for all the images.
pruebalon <- lon[,1836]
pruebalat <- lat[2158,]
#Using these commandos, I create the images, using png command for make figure
##Image data. Header
png("figures/February/viirs2020/2020-02-01_Viirs_2020.jpg",
width=2400, height=1800, res=300 )
##Image data. Body
#day1, 2, 3,4, 5 and c(sea) are values created before.
#Create a store with
BFG <- replace(temperature, c(sea), day1)
color <- colorRampPalette(c("purple", "#00007F", "blue", "#007FFF", "cyan","#7FFF7F", "yellow", "#FF7F00", "red", "#7F0000"))
imagep(pruebalon, pruebalat, log10(BFG), col=color, zlim=log10(c(0.01, 20)), missingColor=1, xlab="Longitude", ylab="Latitude",zlab='log10(chl)')
box()
title(main = "2020-02-01 Viirs 2020",font.main=2,col.main="black", cex.main=1.2)
polygon(coastlineWorld[['longitude']], coastlineWorld[['latitude']], col='black')
#Final image closing process
dev.off()
#The same code for all the next 05 days, that is I want to improve:
png("figures/February/viirs2020/2020-02-02_Viirs_2020.jpg",
width=2400, height=1800, res=300 )
BFG <- replace(temperature, c(sea), day2)
color <- colorRampPalette(c("purple", "#00007F", "blue", "#007FFF", "cyan","#7FFF7F", "yellow", "#FF7F00", "red", "#7F0000"))
imagep(pruebalon, pruebalat, log10(BFG), col=color, zlim=log10(c(0.01, 20)), missingColor=1, xlab="Longitude", ylab="Latitude",zlab='log10(chl)')
box()
title(main = "2020-02-02 Viirs 2020",font.main=2,col.main="black", cex.main=1.2)
polygon(coastlineWorld[['longitude']], coastlineWorld[['latitude']], col='black')
#Final image closing process
dev.off()
png("figures/February/viirs2020/2020-02-03_Viirs_2020.jpg",
width=2400, height=1800, res=300 )
BFG <- replace(temperature, c(sea), day3)
color <- colorRampPalette(c("purple", "#00007F", "blue", "#007FFF", "cyan","#7FFF7F", "yellow", "#FF7F00", "red", "#7F0000"))
imagep(pruebalon, pruebalat, log10(BFG), col=color, zlim=log10(c(0.01, 20)), missingColor=1, xlab="Longitude", ylab="Latitude",zlab='log10(chl)')
box()
title(main = "2020-02-03 Viirs 2020",font.main=2,col.main="black", cex.main=1.2)
polygon(coastlineWorld[['longitude']], coastlineWorld[['latitude']], col='black')
#Final image closing process
dev.off()
png("figures/February/viirs2020/2020-02-04_Viirs_2020.jpg",
width=2400, height=1800, res=300 )
BFG <- replace(temperature, c(sea), day4)
color <- colorRampPalette(c("purple", "#00007F", "blue", "#007FFF", "cyan","#7FFF7F", "yellow", "#FF7F00", "red", "#7F0000"))
imagep(pruebalon, pruebalat, log10(BFG), col=color, zlim=log10(c(0.01, 20)), missingColor=1, xlab="Longitude", ylab="Latitude",zlab='log10(chl)')
box()
title(main = "2020-02-04 Viirs 2020",font.main=2,col.main="black", cex.main=1.2)
polygon(coastlineWorld[['longitude']], coastlineWorld[['latitude']], col='black')
#Final image closing process
dev.off()
png("figures/February/viirs2020/2020-02-05_Viirs_2020.jpg",
width=2400, height=1800, res=300 )
BFG <- replace(temperature, c(sea), day6)
color <- colorRampPalette(c("purple", "#00007F", "blue", "#007FFF", "cyan","#7FFF7F", "yellow", "#FF7F00", "red", "#7F0000"))
imagep(pruebalon, pruebalat, log10(BFG), col=color, zlim=log10(c(0.01, 20)), missingColor=1, xlab="Longitude", ylab="Latitude",zlab='log10(chl)')
box()
title(main = "2020-02-05 Viirs 2020",font.main=2,col.main="black", cex.main=1.2)
polygon(coastlineWorld[['longitude']], coastlineWorld[['latitude']], col='black')
#Final image closing process
dev.off()