# Function to read data from ASCII file
read_data <- function(file_path) {
# Read data from file
data <- as.matrix(read.table(file_path))
return(data)
}
setwd("/home/mauro/Documenti/MODEL_EVAL/SCENARIO/ESM2_rcp2p6/")
# Load required libraries
library(ggplot2)
# Function to read data from ASCII file
read_data <- function(file_path) {
# Read data from file
data <- as.matrix(read.table(file_path))
return(data)
}
source("~/Documenti/MODEL_EVAL/SCENARIO/TEST1.R", echo=TRUE)
source("~/Documenti/MODEL_EVAL/SCENARIO/TEST1.R", echo=TRUE)
source("~/.active-rstudio-document", echo=TRUE)
source("~/Documenti/MODEL_EVAL/SCENARIO/TEST1.R", echo=TRUE)
View(create_boxplot)
View(create_xyplot)
View(data1)
View(data1)
View(data2)
rlang::last_trace()
View(data1)
source("~/.active-rstudio-document", echo=TRUE)
install.packages("ggplot2")
install.packages("ggplot2")
source("~/.active-rstudio-document", echo=TRUE)
install.packages("ggplot2")
install.packages("ggplot2")
source("~/.active-rstudio-document", echo=TRUE)
install.packages("ggplot2")
source("~/Documenti/MODEL_EVAL/SCENARIO/notepad.R", echo=TRUE)
library(ggplot2)
# Sample data for boxplot
set.seed(123)
boxplot_data <- data.frame(
Category = rep(paste0("Case ", 1:10), each = 5),
Value = rnorm(50)
)
source("~/Documenti/MODEL_EVAL/SCENARIO/notepad.R", echo=TRUE)
View(boxplot)
View(boxplot_data)
# Read ASCII data with different columns
data1 <- read.table(file1,
header = TRUE,          # If your file has a header
sep = ",",              # Specify the delimiter (tab, comma, etc.)
fill = TRUE,            # Fill missing columns with NA
na.strings = "NA"       # Define the representation of missing values
)
# Loop to create plots
sites <- c("Collelongo", "Bily_Kriz")
for (i in sites) {
# Read data from ASCII files
file1 <- paste0("3D-CMCC-FEM-v.5.6_", i,"_ESM2_rcp2p6_boxplot")
file2 <- paste0("3D-CMCC-FEM-v.5.6_",i,"_ESM2_rcp2p6_plot_gpp")
setwd("/home/mauro/Documenti/MODEL_EVAL/SCENARIO/ESM2_rcp2p6/")
# Load required libraries
library(ggplot2)
# Function to read data from ASCII file
read_data <- function(file_path) {
# Read data from file
data <- as.matrix(read.table(file_path))
return(data)
}
setwd("/home/mauro/Documenti/MODEL_EVAL/SCENARIO/ESM2_rcp2p6/")
# Load required libraries
library(ggplot2)
# Function to read data from ASCII file
read_data <- function(file_path) {
# Read data from file
data <- as.matrix(read.table(file_path))
return(data)
}
# Function to create boxplot
create_boxplot <- function(data, color) {
# Create boxplot
p <- ggplot(data.frame(y = data), aes(x = 1, y = y)) +
geom_boxplot(fill = color) +
theme_minimal() +
labs(x = NULL, y = NULL) +
coord_flip() +
theme(legend.position = "none")
return(p)
}
# Function to create xy plot
create_xyplot <- function(data, color) {
# Create xy plot
p <- ggplot(data.frame(data), aes(x = X, y = Y)) +
geom_point(color = color, alpha = 0.5) +
theme_minimal() +
labs(x = NULL, y = NULL) +
theme(legend.position = "none")
return(p)
source("~/Documenti/MODEL_EVAL/SCENARIO/TEST1.R", echo=TRUE)
source("~/Documenti/MODEL_EVAL/SCENARIO/TEST1.R", echo=TRUE)
source("~/Documenti/MODEL_EVAL/SCENARIO/TEST1.R", echo=TRUE)
source("~/Documenti/MODEL_EVAL/SCENARIO/TEST1.R", echo=TRUE)
View(data1)
View(create_xyplot)
View(data1)
View(data2)
source("~/Documenti/MODEL_EVAL/SCENARIO/TEST1.R", echo=TRUE)
# Function to read data from ASCII file
read_data <- function(file_path) {
# Read data from file
data <- as.matrix(read.table(file_path))
return(data)
}
# Function to create boxplot
create_boxplot <- function(data, color) {
# Create boxplot
p <- ggplot(data.frame(y = data), aes(x = 1, y = y)) +
geom_boxplot(fill = color) +
theme_minimal() +
labs(x = NULL, y = NULL) +
coord_flip() +
theme(legend.position = "none")
return(p)
}
# Function to create xy plot
create_xyplot <- function(data, color) {
# Create xy plot
p <- ggplot(data.frame(data), aes(x = X, y = Y)) +
geom_point(color = color, alpha = 0.5) +
theme_minimal() +
labs(x = NULL, y = NULL) +
theme(legend.position = "none")
return(p)
}
# Loop to create plots
sites <- c("Collelongo", "Bily_Kriz")
for (i in sites) {
# Read data from ASCII files
file1 <- paste0("3D-CMCC-FEM-v.5.6_", i,"_ESM2_rcp2p6_boxplot")
file2 <- paste0("3D-CMCC-FEM-v.5.6_",i,"_ESM2_rcp2p6_plot_gpp")
# data1 <- read_data(file1)
# data2 <- read_data(file2)
data1 <- read.table(file1,
header = TRUE,          # If your file has a header
sep = ",",              # Specify the delimiter (tab, comma, etc.)
fill = TRUE,            # Fill missing columns with NA
na.strings = "NA"       # Define the representation of missing values
)
data2 <- read.table(file2,
header = TRUE,          # If your file has a header
sep = ",",              # Specify the delimiter (tab, comma, etc.)
fill = TRUE,            # Fill missing columns with NA
na.strings = "NA"       # Define the representation of missing values
)
# If you have a CSV file, you can use read.csv() with similar parameters
# data <- read.csv("your_file_path.csv", header = TRUE, fill = TRUE, na.strings = "NA")
# View the structure of the data
str(data)
# View the first few rows of the data
head(data)
# Define colors
colors <- c("green", "yellow", "red")
# Create boxplot and xy plot
boxplot <- create_boxplot(data1, colors[i])
xyplot <- create_xyplot(data2, colors[i])
# Combine plots
combined_plot <- gridExtra::grid.arrange(boxplot, xyplot, ncol = 2)
# Print combined plot
print(combined_plot)
}
source("~/Documenti/MODEL_EVAL/SCENARIO/TEST1.R", echo=TRUE)
source("~/Documenti/MODEL_EVAL/SCENARIO/TEST1.R", echo=TRUE)
source("~/Documenti/MODEL_EVAL/SCENARIO/TEST1.R", echo=TRUE)
source("~/Documenti/MODEL_EVAL/SCENARIO/TEST1.R", echo=TRUE)
View(legend_plot)
ls
source("~/.active-rstudio-document", echo=TRUE)
View(data)
# Loop to create plots
sites <- c("Collelongo", "Bily_Kriz")
for (i in sites) {
# Read data from ASCII files
file1 <- paste0("3D-CMCC-FEM-v.5.6_", i,"_ESM2_rcp2p6_boxplot")
file2 <- paste0("3D-CMCC-FEM-v.5.6_",i,"_ESM2_rcp2p6_plot_gpp")
# data1 <- read_data(file1)
# data2 <- read_data(file2)
data1 <- read.table(file1,
header = TRUE,          # If your file has a header
sep = ",",              # Specify the delimiter (tab, comma, etc.)
fill = TRUE,            # Fill missing columns with NA
na.strings = "NA"       # Define the representation of missing values
)
data2 <- read.table(file2,
header = TRUE,          # If your file has a header
sep = ",",              # Specify the delimiter (tab, comma, etc.)
fill = TRUE,            # Fill missing columns with NA
na.strings = "NA"       # Define the representation of missing values
)
source("~/Documenti/MODEL_EVAL/SCENARIO/TEST1.R", echo=TRUE)
source("~/Documenti/MODEL_EVAL/SCENARIO/TEST1.R", echo=TRUE)
# View the structure of the data
str(data)
# View the first few rows of the data
head(data)
# Define colors
colors <- c("green", "yellow", "red")
# Create boxplot and xy plot
boxplot <- create_boxplot(data1, colors[i])
xyplot <- create_xyplot(data2, colors[i])
# Combine plots
combined_plot <- gridExtra::grid.arrange(boxplot, xyplot, ncol = 2)
# Print combined plot
print(combined_plot)
}
# Add legend at bottom left
legend_plot <- ggplot() +
geom_blank() +
theme_void() +
scale_fill_manual(values = colors, name = "Legend", labels = c("Plot 1", "Plot 2", "Plot 3"))
# Print legend plot
print(legend_plot)
View(data1)
source("~/.active-rstudio-document", echo=TRUE)
source("~/Documenti/MODEL_EVAL/SCENARIO/TEST1.R", echo=TRUE)
source("~/Documenti/MODEL_EVAL/SCENARIO/TEST1.R", echo=TRUE)
View(data1)
source("~/.active-rstudio-document", echo=TRUE)
# Load required libraries
library(ggplot2)
# Function to read data from ASCII file
read_data <- function(file_path) {
# Read data from file
data <- as.matrix(read.table(file_path))
return(data)
}
# Function to create boxplot
create_boxplot <- function(data, color) {
# Create boxplot
p <- ggplot(data.frame(y = data), aes(x = "interval_year", y = "gpp_10y_avg")) +
geom_boxplot(fill = color) +
theme_minimal() +
labs(x = NULL, y = NULL) +
coord_flip() +
theme(legend.position = "none")
return(p)
}
View(create_boxplot)
View(read_data)
# Function to create xy plot
create_xyplot <- function(data, color) {
# Create xy plot
p <- ggplot(data.frame(data), aes(x = 1, y = "interval_year")) +
geom_point(color = color, alpha = 0.5) +
theme_minimal() +
labs(x = NULL, y = NULL) +
theme(legend.position = "none")
return(p)
}
View(create_xyplot)
# Function to create xy plot
create_xyplot <- function(data, color) {
# Create xy plot
p <- ggplot(data.frame(data), aes(x = "interval_year", y = "gpp_10y_avg")) +
geom_point(color = color, alpha = 0.5) +
theme_minimal() +
labs(x = NULL, y = NULL) +
theme(legend.position = "none")
return(p)
}
# Loop to create plots
sites <- c("Collelongo", "Bily_Kriz")
for (i in sites) {
# Read data from ASCII files
file1 <- paste0("3D-CMCC-FEM-v.5.6_", i,"_ESM2_rcp2p6_boxplot")
file2 <- paste0("3D-CMCC-FEM-v.5.6_",i,"_ESM2_rcp2p6_plot_gpp")
# data1 <- read_data(file1)
# data2 <- read_data(file2)
data1 <- read.table(file1,
header = TRUE,          # If your file has a header
sep = ",",              # Specify the delimiter (tab, comma, etc.)
fill = TRUE,            # Fill missing columns with NA
na.strings = "NA"       # Define the representation of missing values
)
data2 <- read.table(file2,
header = TRUE,          # If your file has a header
sep = ",",              # Specify the delimiter (tab, comma, etc.)
fill = TRUE,            # Fill missing columns with NA
na.strings = "NA"       # Define the representation of missing values
)
View(read_data)
# View the structure of the data
str(data)
# View the first few rows of the data
head(data)
# Define colors
colors <- c("green", "yellow", "red")
# Create boxplot and xy plot
boxplot <- create_boxplot(data1, colors[i])
xyplot <- create_xyplot(data2, colors[i])
# Combine plots
combined_plot <- gridExtra::grid.arrange(boxplot, xyplot, ncol = 2)
# Print combined plot
print(combined_plot)
}
View(data2)
p <- ggplot(data.frame(y = data), aes(x = "interval_year", y = "gpp_10y_avg")) +
source("~/.active-rstudio-document", echo=TRUE)
View(xyplot)
source("~/Documenti/MODEL_EVAL/SCENARIO/TEST1.R", echo=TRUE)
source("~/.active-rstudio-document", echo=TRUE)
source("~/.active-rstudio-document", echo=TRUE)
# Read data from ASCII file
# Loop to create plots
sites <- c("Collelongo", "Bily_Kriz")
for (i in sites) {
# Read data from ASCII files
file1 <- paste0("3D-CMCC-FEM-v.5.6_", i,"_ESM2_rcp2p6_boxplot")
file2 <- paste0("3D-CMCC-FEM-v.5.6_",i,"_ESM2_rcp2p6_plot_gpp")
# data1 <- read_data(file1)
# data2 <- read_data(file2)
data1 <- read.table(file1,
header = TRUE,          # If your file has a header
sep = ",",              # Specify the delimiter (tab, comma, etc.)
fill = TRUE,            # Fill missing columns with NA
na.strings = "NA"       # Define the representation of missing values
)
data2 <- read.table(file2,
header = TRUE,          # If your file has a header
sep = ",",              # Specify the delimiter (tab, comma, etc.)
fill = TRUE,            # Fill missing columns with NA
na.strings = "NA"       # Define the representation of missing values
)
# Create box plot
boxplot(data, main="Box Plot of Your Data", ylab="Data Values")
# Optionally, you can save the plot as an image file
# For example, to save it as a PNG file:
# png("boxplot.png")
# boxplot(data, main="Box Plot of Your Data", ylab="Data Values")
# dev.off()
source("~/.active-rstudio-document", echo=TRUE)
source("~/.active-rstudio-document", echo=TRUE)
source("~/.active-rstudio-document", echo=TRUE)
source("~/.active-rstudio-document", echo=TRUE)
source("~/.active-rstudio-document", echo=TRUE)
source("~/.active-rstudio-document", echo=TRUE)
source("~/.active-rstudio-document", echo=TRUE)
source("~/.active-rstudio-document", echo=TRUE)
source("~/.active-rstudio-document", echo=TRUE)
source("~/.active-rstudio-document", echo=TRUE)
View(data_1d)
View(data_2d)
View(data_1d)
source("~/.active-rstudio-document", echo=TRUE)
source("~/.active-rstudio-document", echo=TRUE)
# Carica le librerie necessarie
library(grDevices)
# Definisci una funzione per generare colori gradienti
color.gradient <- function(color.start, color.end, n, interp.type = "rgb") {
color.start <- col2rgb(color.start)
color.end <- col2rgb(color.end)
R <- seq(color.start[1], color.end[1], length.out = n)
G <- seq(color.start[2], color.end[2], length.out = n)
B <- seq(color.start[3], color.end[3], length.out = n)
if(interp.type == "rgb") {
return(rgb(R, G, B, maxColorValue = 255))
} else {
return(trans3d(R, G, B))
}
}
setwd("~/Documenti/MODEL_EVAL/SCENARIO/ESM2_rcp2p6")
# Carica le librerie necessarie
library(grDevices)
# Definisci una funzione per generare colori gradienti
color.gradient <- function(color.start, color.end, n, interp.type = "rgb") {
color.start <- col2rgb(color.start)
color.end <- col2rgb(color.end)
R <- seq(color.start[1], color.end[1], length.out = n)
G <- seq(color.start[2], color.end[2], length.out = n)
B <- seq(color.start[3], color.end[3], length.out = n)
if(interp.type == "rgb") {
return(rgb(R, G, B, maxColorValue = 255))
} else {
return(trans3d(R, G, B))
}
}
# Definisci i nomi dei file
file_names <- c("3D-CMCC-FEM-v.5.6_Bily_Kriz_ESM2_rcp2p6_boxplot", "3D-CMCC-FEM-v.5.6_Bily_Kriz_ESM2_rcp2p6_plot_gpp")
# Ciclo per caricare i file, leggere righe e colonne, e creare grafici
for (i in 1:length(file_names)) {
# Carica il file
data <- read.table(file_names[i], header = TRUE)
# Estrai righe e colonne
rows <- nrow(data)
cols <- ncol(data)
# Crea nuovi colori gradienti per ogni iterazione
colors <- color.gradient("green", "red", cols)
# Grafici
par(mfrow = c(2, 1)) # Divide la finestra grafica in due
# Istogramma
barplot(colSums(data), col = colors, main = paste("Istogramma - File", i), xlab = "Colonne", ylab = "Frequenza")
# XY plot
plot(1:rows, data[1,], type = "l", col = colors, main = paste("XY Plot - File", i), xlab = "Righe", ylab = "Valore")
# Legenda
legend("bottom", legend = colnames(data), fill = colors, bty = "n", title = "Colonne")
# Salva l'immagine
filename <- paste("grafico_", i, ".png", sep = "")
dev.copy(png, filename)
dev.off()
}
View(data)
setwd("/home/mauro/Documenti/MODEL_EVAL/SCENARIO/ESM2_rcp2p6/")
# Load required libraries
library(ggplot2)
# Function to read data from ASCII file
read_data <- function(file_path) {
# Read data from file
data <- as.matrix(read.table(file_path))
return(data)
}
View(read_data)
# Function to create boxplot
create_boxplot <- function(data, color) {
# Create boxplot
p <- ggplot(data.frame(y = data), aes(x = "interval_year", y = "gpp_10y_avg")) +
geom_boxplot(fill = color) +
theme_minimal() +
labs(x = NULL, y = NULL) +
coord_flip() +
theme(legend.position = "none")
return(p)
}
# Function to create xy plot
create_xyplot <- function(data, color) {
# Create xy plot
p <- ggplot(data.frame(data), aes(x = "interval_year", y = "gpp_10y_avg")) +
geom_point(color = color, alpha = 0.5) +
theme_minimal() +
labs(x = NULL, y = NULL) +
theme(legend.position = "none")
return(p)
}
# Loop to create plots
source("~/.active-rstudio-document", echo=TRUE)
View(color.gradient)
source("~/Documenti/MODEL_EVAL/SCENARIO/TEST2.R", echo=TRUE)
source("~/Documenti/MODEL_EVAL/SCENARIO/TEST2.R", echo=TRUE)
source("~/Documenti/MODEL_EVAL/SCENARIO/TEST2.R", echo=TRUE)
View(data2)
setwd("/home/mauro/Documenti/MODEL_EVAL/SCENARIO/ESM2_rcp2p6/")
# Load required libraries
library(ggplot2)
# Function to read data from ASCII file
read_data <- function(file_path) {
# Read data from file
data <- as.matrix(read.table(file_path))
return(data)
}
# Function to create boxplot
create_boxplot <- function(data, color) {
# Create boxplot
p <- ggplot(data.frame(y = data), aes(x = "interval_year", y = "gpp_10y_avg")) +
geom_boxplot(fill = color) +
theme_minimal() +
labs(x = NULL, y = NULL) +
coord_flip() +
theme(legend.position = "none")
return(p)
}
# Function to create xy plot
create_xyplot <- function(data, color) {
# Create xy plot
p <- ggplot(data.frame(data), aes(x = "interval_year", y = "gpp_10y_avg")) +
geom_point(color = color, alpha = 0.5) +
theme_minimal() +
labs(x = NULL, y = NULL) +
theme(legend.position = "none")
return(p)
}
# Loop to create plots
sites <- c("Collelongo", "Bily_Kriz")
for (i in sites) {
# Read data from ASCII files
file1 <- paste0("3D-CMCC-FEM-v.5.6_", i,"_ESM2_rcp2p6_boxplot")
file2 <- paste0("3D-CMCC-FEM-v.5.6_",i,"_ESM2_rcp2p6_plot_gpp")
# data1 <- read_data(file1)
# data2 <- read_data(file2)
data1 <- read.table(file1,
header = TRUE,          # If your file has a header
sep = ",",              # Specify the delimiter (tab, comma, etc.)
fill = TRUE,            # Fill missing columns with NA
na.strings = "NA"       # Define the representation of missing values
)
data2 <- read.table(file2,
header = TRUE,          # If your file has a header
sep = ",",              # Specify the delimiter (tab, comma, etc.)
fill = TRUE,            # Fill missing columns with NA
na.strings = "NA"       # Define the representation of missing values
)
# View the structure of the data
str(data)
# View the first few rows of the data
head(data)
# Define colors
colors <- c("green", "yellow", "red")
# Create boxplot and xy plot
boxplot <- create_boxplot(data1, colors[i])
xyplot <- create_xyplot(data2, colors[i])
# Combine plots
combined_plot <- gridExtra::grid.arrange(boxplot, xyplot, ncol = 2)
# Print combined plot
print(combined_plot)
}
source("~/Documenti/MODEL_EVAL/SCENARIO/TEST1.R", echo=TRUE)
source("~/Documenti/MODEL_EVAL/SCENARIO/TEST1.R", echo=TRUE)
