plotMap() is one of the best antaresViz function. But to be able to change color areas, we have to provide a layout. This document will show how to build a useful layout.
Install antaresViz with :
install.packages("antaresViz")
Before showing how to use mapLayout(), we must import our data.
#here import your data
refStudy <- "pathToRefStudy"
#reference study
optsRef <- setSimulationPath(path = refStudy, simulation = -3)
refData <- readAntares(areas = "all",
links = "all",
opts = optsRef)
This function will launch an application that let you place your areas. Click “Next” at each step and then click “Done”.
#import x, y areas position
posLayout <- readLayout()
mlDefault <- mapLayout(layout = posLayout)
saveRDS(object = mlDefault,
file = "inst/mlDefault.RDS")
You can visualize your layout with plotMapLayout.
mlDefaultR <- readRDS(file = "inst/mlDefault.RDS")
plotMapLayout(mlDefaultR)
plotMap can now use this layout to represent your areas.
plotMap(x = refData,
mapLayout = mlDefaultR,
interactive = FALSE,
colAreaVar = "LOAD",
colLinkVar = "FLOW LIN.",
type = "avg")
If you need states details but not having one area per state, the map will be incomplete for some countries, plotting only states with area. So you can choose to aggregate the states of the countries. This is done using a nearest states algorithm. The result is available only after layout validation.
We will illustrate how mapLayout() works with the option merge states set to false.
mlStatesF <- mapLayout(layout = posLayout)
saveRDS(object = mlStatesF,
file = "inst/mlStatesF.RDS")
You can visualize your layout with plotMapLayout.
mlDefaultSF <- readRDS(file = "inst/mlStatesF.RDS")
plotMapLayout(mlDefaultSF)
States are not aggregated. plotMap can use this layout to represent your areas but the result may not be very nice.
plotMap(x = refData,
mapLayout = mlDefaultSF,
interactive = FALSE,
colAreaVar = "LOAD",
colLinkVar = "FLOW LIN.",
type = "avg")
If you want a beautiful map you must set merge states to TRUE.
mlStatesT <- mapLayout(layout = posLayout)
saveRDS(object = mlStatesT,
file = "inst/mlStatesT.RDS")
#!
You can check your layout with plotMapLayout.
mlDefaultST <- readRDS(file = "inst/mlStatesT.RDS")
plotMapLayout(mlDefaultST)
States are now aggregated, the result from plotMap() is a little nicer.
plotMap(x = refData,
mapLayout = mlDefaultST,
interactive = FALSE,
colAreaVar = "LOAD",
colLinkVar = "FLOW LIN.",
type = "avg")
Some countries like UK or Belgium are firstly rendered in multiple and diffrent area. You can so choose to finally use this countries as one single area on the map.
We will illustrate how mapLayout() works with the option merge countries set to false.
mlCounF <- mapLayout(layout = posLayout)
saveRDS(object = mlCounF,
file = "inst/mlCounF.RDS")
You can visualize your layout with plotMapLayout. Countries are not aggregated.
mlCountF <- readRDS(file = "inst/mlCounF.RDS")
plotMapLayout(mlCountF)
For United Kingdom, we will have countries details in plotMap(). Each country (England, Scotland, Wales and Nothern Ireland) will have a color that represent the parameter colAreaVar here LOAD.
plotMap(x = refData,
mapLayout = mlCountF,
interactive = FALSE,
colAreaVar = "LOAD",
colLinkVar = "FLOW LIN.",
type = "avg",
typeSizeAreaVars = TRUE,
aliasSizeAreaVars = c("generation", "renewable"),
sizeMiniPlot = TRUE,
areaChartType = "pie")
If we want to aggregate countries, we have to set merge countries to TRUE.
mlCounT <- mapLayout(layout = posLayout)
saveRDS(object = mlCounT,
file = "inst/mlCounT.RDS")
Countries are now aggregated.
mlCountT <- readRDS(file = "inst/mlCounT.RDS")
plotMapLayout(mlCountT)
Now, for United Kingdom, we will have one color representing the parameter colAreaVar for the four countries.
plotMap(x = refData,
mapLayout = mlCountT,
interactive = FALSE,
colAreaVar = "LOAD",
colLinkVar = "FLOW LIN.",
type = "avg",
typeSizeAreaVars = TRUE,
aliasSizeAreaVars = c("generation", "renewable"),
sizeMiniPlot = TRUE,
areaChartType = "pie")
A user can choose to import a different layout from the default one. The default one is obtained from spMaps::getSpMaps(). Anyone can download some SpatialPolygonsDataFrame, for example, from here.
Here, we have choose : - Spain, Level 1 ; - Belgium, Level 1 ; - France, Level 2.
#before using it in mapLayout, we must read all the files
sp1 <- readRDS(file = "inst/sp/gadm36_ESP_1_sp.rds")
be1 <- readRDS(file = "inst/sp/gadm36_BEL_1_sp.rds")
fr2 <- readRDS(file = "inst/sp/gadm36_FRA_2_sp.rds")
#same level use rbind
spBe <- rbind(sp1, be1)
#different level use union
spBeFr <- union(spBe, fr2)
mlNewMap <- mapLayout(layout = posLayout, map = spBeFr)
saveRDS(object = mlNewMap,
file = "inst/mlNewMap.RDS")
…….
mlNewMap <- readRDS(file = "inst/mlNewMap.RDS")
plotMapLayout(mlNewMap)
…….
plotMap(x = refData,
mapLayout = mlNewMap,
interactive = FALSE,
colAreaVar = "LOAD",
colLinkVar = "FLOW LIN.",
type = "avg",
typeSizeAreaVars = TRUE,
aliasSizeAreaVars = c("generation", "renewable"),
sizeMiniPlot = TRUE,
areaChartType = "pie")