# Make 3 identical objects as scenarios; let's assume these represent the
# years 2000, 2005 and 2010.
library(chillR)
# Compute chill responses for KA_weather data
chill <- tempResponse(stack_hourly_temps(
fix_weather(KA_weather[which(KA_weather$Year > 2006), ]),
latitude = 50.4), Start_JDay = 305, End_JDay = 60)
# Simulated scenarios labels
past_labels <- c(2000, 2005, 2010)
# Models labels
models_labels <- c("Climate model 1", "Climate model 2",
"Climate model 3")
# Add named elements to past and future scenarios
scenario_results_past <- list(`2000` = chill,
`2005` = chill,
`2010` = chill)
scenario_results_future <- list(`Climate model 1` = chill,
`Climate model 2` = chill,
`Climate model 3` = chill)
# Define the climate scenario
climate_scenario_list <- list(list(data = scenario_results_past,
caption = c("Historic", "data"),
time_series = TRUE,
labels = past_labels,
historic_data = chill),
list(data = scenario_results_future,
caption = c("Scenario 1", "2050"),
labels = models_labels),
list(data = scenario_results_future,
caption = c("Scenario 1", "2075"),
labels = models_labels),
list(data = scenario_results_future,
caption=c("Scenario 1", "2100"),
labels = models_labels),
list(data = scenario_results_future,
caption=c("Scenario 2", "2040"),
labels = models_labels),
list(data = scenario_results_future,
caption=c("Scenario 2", "2080"),
labels = models_labels))
# Plot the climate scenarios
plot_scenarios(climate_scenario_list, metric = 'Chill_Portions',
add_historic = TRUE, size = 2, shape = 3, color = 'blue',
outlier_shape = 12, historic_color = 'skyblue',
group_by = c("Year", "Scenario"))
## Plot scenarios modifying the whole text in the plot
## We will comment the next examples to reduce the running time in CRAN
## submissions...
# plot_scenarios(scenario_list = climate_scenario_list, metric = 'Chill_Portions',
# add_historic = TRUE, size = 2, shape = 3, color = 'blue',
# outlier_shape = 12, historic_color = 'skyblue',
# group_by = c("Scenario", "Year"),
# y_axis_name = "Acumulacion de frio en CP",
# x_axis_name = "Tiempo",
# legend_title = "Modelo climatico",
# legend_labels = c("Modelo 1", "Modelo 2", "Modelo 3"),
# panel_labels = list(Historic = "Historico",
# Scenario = c("Escenario 1",
# "Escenario 2"),
# Year = list(`Escenario 1` = c("Futuro cercano",
# "Futuro medio",
# "Future lejano"),
# `Escenario 2` = c("Futuro cercano",
# "Futuro medio"))))
## Since the output is a ggplot object, it is possible to continue
## modifying some general aspects of the plot
## Define the basic plot
# plot <- plot_scenarios(climate_scenario_list, metric = 'Chill_Portions',
# add_historic = TRUE, size = 2, shape = 3, color = 'blue',
# outlier_shape = 12, historic_color = 'skyblue')
## Example to change the color of the climate model scale
# plot & ggplot2::scale_fill_brewer(type = 'qual')
## Modify the format of axis title and axis text
# plot & ggplot2::theme(axis.title = ggplot2::element_text(size = 14,
# family = 'serif'),
# axis.text = ggplot2::element_text(face = 'bold',
# color = 'blue'))
Run the code above in your browser using DataLab