Introduction

Urban agriculture is becoming one of the pillars of the urban ecological transition (Säumel et al., 2019). Likewise, urban agriculture might have a key role ensuring food security in an urbanized planet (Barthel et al., 2015). As a consequence, some research has paid attention on the actual or potential food production of urban agriculture (Grafius et al., 2020; Richardson & Moskal, 2016). However, some others authors argued that the importance of urban agriculture does not reside in its ability to produce food but in the social benefits it provides, such as public health (Soga et al., 2017) and social cohesion (Säumel et al., 2019). Moreover, other authors stated that urban agriculture can provide environmental benefits as well, such as climate regulation (Clinton et al., 2018) or water runoff prevention (Gittleman et al., 2017).

However, there is a lack of systematic quantification of the benefits provided by urban agriculture (Langemeyer et al., 2021a). For instance, there is no clear evidence to what extent urban agriculture could contribute to reduce the urban heat island (Lin et al., 2015) or to a greener economy (Säumel et al., 2019). However, most studies have been focused on a single initiative and one benefit (Artmann & Sartison, 2018).

Therefore, decision-makers, who are responsible of leading the urban transitions to more sustainable and resilient cities, are orphan of evidence in how to implement urban agriculture to maximize its impact on sustainability. Yet, several studies have provided some insights that can guide the implementation of urban agriculture. For instance, some models explore the rainwater harvesting potential of urban agriculture (Gittleman et al., 2017; Lupia et al., 2017). Broader, Gómez-Villarino and Ruiz-Garcia (2021) developed guidelines to maximize ecosystem services through urban agriculture by applying adaptive design and providing a battery of indicators. And, as expected, many models have been developed to quantify food production and food security provided by urban agriculture by simulating a myriad of scenarios with different types of urban agriculture virtually implemented such as rooftop gardens, community gardens or private citizen-led gardens (Grafius et al., 2020; Grewal & Grewal, 2012; Hsieh et al., 2017; MacRae et al., 2010). Yet, a transferable model (applicable to any city) to assess simultaneously several environmental and social benefits is lacking.

Hence, our goal is to provide a tool to estimate those multiple benefits of urban agriculture that help decision-makers to strategically implement urban agriculture solutions. We developed the estimations for eight indicators measuring urban agriculture benefits and a functionality to create scenarios of urban agriculture based on the proportion of elements to be transformed to urban agriculture and on which elements will be transformed. Likewise, we packed all those functionalities in an R package called ediblecity. In the Methods, we present the interface of the package and then we illustrate the usefulness by applying the model to a neighborhood of Girona (Spain).

While the package offers default values for nearly all necessary parameters, it's worth noting that these defaults have been tailored to our specific example, which focuses on a mid-sized Western Mediterranean European city. Nevertheless, it's important to emphasize that users have the flexibility to customize all parameters according to their specific context.

Methods

Implementation: the model under the package

All the equations and algorithms to model the benefits of urban agriculture were encapsulated in an R package (R Core Team, 2022), using one function for each indicator and one function to create scenarios. The package was created using R version 4.2.1 (R Core Team, 2022) in RStudio desktop v. 2022.07.02. The package structure was assisted by the package devtools (Wickham et al., 2022b) following the principles in Wickham and Bryan (2022). Likewise, the documentation of the functions was assisted by the package roxygen2 (Wickham et al., 2022a). The dependencies of the package are:

Urban representation of the city of interest. The ediblecity package provides eight functions to estimate eight different indicators and a function to generate scenarios. It takes, as a basis, a spatial representation of a city (or a part of a city) as a GIS layer. This representation must have one attribute indicating the land uses of the city, such as gardens, streets, rooftops, etc. Some indicators require specific information to be included in the representation. This is explained in each indicator’s section.

The package includes the representation of Sant Narcís, a neighbourhood of Girona (Spain) as an example of an urban representation (Figure 1). This example can help the users to create the representation of their cities of interest. In the Table 1 below, a sample with one element of each type is shown. The representation is provided as an sf object, which is a class for spatial data in R implemented by package sf (Pebesma, 2018b)

37edffb8-6b20-40a9-b5be-309b2f37c984_figure1.gif

Figure 1. The urban representation included in the ‘ediblecity‘ package as example.

Table 1. Structure of the urban representation example.

ColumnDescription
land_useA category representing the urban elements
land_use_verboseA more detailed category for the element, for example, if it is residential
floorsThe number of floors of the element, 0 for non-built
areaThe surface of the element
flat_areaThe surface of the element that is flat (slope < 5⍛)
edible_areaThe surface that is used to grow edible plants. Only applicable to urban agriculture solutions

Along with the example for an urban representation, the ediblecity package also includes a data.frame with the default attributes of each green typology in the urban representation used to estimate the indicators (Table 2). This includes types of urban agriculture along with other types of green infrastructure. However, the user can provide their own attributes to estimate any indicator. In city_land_uses there are other columns not shown in Table 2, they are logical variables (i.e. TRUE/FALSE) used internally by the package to select urban agriculture elements.

Table 2. General attributes of the elements of urban green used to estimate the indicators.

land_usespGreenno2_seq1no2_seq2food1food2CN1CN2
Edible private garden0.60.070.090.26.68588
Community garden1.00.070.090.22.28588
Commercial garden1.00.070.094.06.68585
Rooftop garden1.00.070.070.22.26788
Hydroponic rooftop1.00.070.079.019.09898
Arable land0.60.000.074.06.68588
Normal garden0.60.070.071.01.07486
Permanent crops0.60.090.094.06.66577
Vacant1.00.070.091.01.07487
Grass1.00.070.071.01.07486
Mulcher1.00.000.001.01.08888
Raised bed1.00.070.071.01.06788
Trees1.00.110.111.01.07077
Vegetated pergola1.00.070.071.01.09898

pGreen is the proportion of green of the urban element. In urban agriculture solutions, this is overridden by the attribute edible_area. The following attributes come in pairs (min, max) to consider uncertainty in the estimations. The functions use a random value within the range provided by the pair of values for each element in the city. We used a random uniform distribution, i.e., all values within the rage have the same probability of being picked. no2_seq is the capacity of the element to capture NO2 in gr/s. food is the food productivity in kg/m2 and CN is their curve number, used to calculate infiltration rates. The details are provided in following sections.

Indicators estimated. The current version of the package includes 8 indicators related to various urban challenges defined, as defined in part by a handbook of indicators to evaluate the impact of nature-based solutions (Dumitru & Wendling, 2021) From this source, we chose 8 indicators that meet the following criteria: (1) Measurability: The indicators can be quantitatively measured based on the area or location. (2) Direct Influence: Urban agriculture (UA) has a direct impact on the indicators, meaning that changes in UA will affect the indicator's values. (3) Relevance to UC: The indicators are directly linked to a specific UC, and at least indirectly connected to another UC, allowing us to capture multiple dimensions of urban sustainability. By considering these criteria, we ensured that the selected indicators provide a holistic understanding of the impact of UA on urban challenges.

It's worth noting that the tool is open source. Therefore, new indicators can be added in the future either by the creators or by other users interested in specific aspects of UA.

Urban heat island The urban heat island is a measure of how urban agriculture can contribute to climate change adaptation, specifically to adapt cities to the increasing heat waves (Langemeyer et al., 2021b). The indicator uses the equation developed by Theeuwes et al. (2017), which was validated in 14 cities. It calculates the difference in air temperature between the urban street canyon and the rural environment. To calculate this indicator, the user must provide a raster representing the sky view factor (SVF), which describes the proportion of the unobstructed hemisphere above a certain location. SAGA, a collection of open-source algorithms for geocomputation, provides an algorithm to calculate the SVF (Conrad, 2008).

UHI=1N∑i=1N(2−SVFi−Fvegi)×QqlCair×Pair×ΔT3U4

where Fveg is the proportion of vegetation in cell i; Qql is the daily average global radiation (in W/m2/hour); Cair is the air heat capacity (in J); Pair is air density (in kg/m3); ∆T is the difference between the maximum and minimum daily average temperatures (in ⍛C); and U is the daily average wind speed (in m/s).

The indicator to estimate the urban heat island is implemented by the package under the function UHI (code snippet 1). The user must provide the urban representation (x) and the raster with SVF values (SVF). The green_df argument is a data.frame with the proportion of green of each land_use in the urban representation (Fveg in the equation). All the meteorological arguments are provided by default, based on the example provided (Mediterranean climate). However, the user can override them to provide values of their city of interest.

The function returns by default a summary of statistics of the UHI in x (min, 25%, 50%, mean, 75% and max values). If the argument return_raster is set to TRUE, the function returns a raster as stars object (Pebesma, 2021) with the UHI values. If verbose is set to TRUE, then the function returns a vector (i.e. an array) with the UHI in each cell. Both use the same resolution than SVF.

Code snippet 1: Function and arguments to estimate urban heat island.

UHI(
  x,                              # Urban representation
  SVF,                           # Raster with the sky view factor
  green_df = NULL,             # Fveg in the UHI equation
  Qql = 6.11,                   # Daily average global radiation
  Cair = 1007,                  # Air heat capacity
  Pair = 1.14,                  # Air density
  Tmax = 30.8,                  # Maximum daily average temperature
  Tmin = 20,                    # Minimum daily average temperature
  windspeed = 2.77,            # Average wind speed
  return_raster = FALSE,      # Should function return a raster or numeric values?
  verbose = FALSE              # Should the function return all the values or a summary?
)

Runoff prevention Surface runoff is the flow of water occurring on the ground surface when excess rainwater can no longer sufficiently rapidly infiltrate in the soil. Hence, runoff mitigation contributes to climate resilience since rain events will increase due to climate change (Shukla et al., 2019). The indicator measures the runoff in the city after a specific 24-hours rain event as well as the amount of rainwater harvested by harvesting systems. We departed from the model developed by the Soil Conservation Service (USDA), known as SCS runoff curve number method (Cronshey et al., 1985).

Q=(P−Ia)2(P−Ia)+S

where Q is the runoff in mm; P is the rainfall volume in mm; Ia is the initial abstraction (all losses before runoff begins); and S is the potential soil moisture retention, which is a function of the curve number (which is determined by hydrologic soil group, see Cronshey, Roberts, and Miller (1985) for more details on the method). The SCS generalizes Ia as 0.2S, we modified this generalization to include the rainwater harvested:

Ia=0.2S+∑i=1Nmin{Rh,Ws}i

where Rh is the potential water harvested by the element i, calculated as the amount of water fallen on the surface of adjacent higher buildings that are not used for gardening (in litres); Ws is the water storage capacity of the element i in terms of tank volume (in litres). From both, the minimum is used to calculate Ia.

The runoff_prev function estimates the runoff (Q in the equation) as well as the total rainfall in x and the total rainwater harvested in cubic meters (code snippet 2). Along with the urban representation (x), the user must provide a data.frame (runoff_df argument) with four variables: land use, minimum and maximum curve numbers and a logical variable indicating whether the land use (a urban garden, a building,. . . ) has potential to harvest rainwater. The argument rain allows to set the rain event (in mm), which must be defined by the user. The curve number of each element is randomized within this range provided in runoff_df. If runoff_df is not provided, city_land_uses is used instead. Following, floors_field is the name of attribute in x that specifies the number of floors of each element; harvest_dist (in m) is the maximum distance to consider that a building is adjacent to the element; and tank_size is a range for the volume of the rainwater tank, proportional to the surface of the element (in l/m2). The volume of each tank in the city is randomized within this range and multiplied by the element where they are located. All randomizations follow a random uniform distribution within the correspondent range.

Code snippet 2: Function and arguments to estimate runoff prevention

runoff_prev(
  x,                              # Urban representation
  runoff_df = NULL,             # A data.frame with land use values
  rain = 85,                     # Rain event in mm.
  floors_field = "floors",     # Variable in 'x' containing the number of floors of each element
  harvest_dist = 10,            # Maximum distance to consider for rainwater harvesting surfaces
  tank_size = c(0, 45)          # Range for the size of tanks in m3
)

Green areas accessibility This indicator calculates the distance from each home to the closest public green area and return a summary of statistics (min, 25%, 50%, mean, 75% and max). It includes the possibility to exclude areas smaller than a threshold. The function to calculate these distances is green_distance (code snippet 3). It requires, as usual, the urban representation (x) and a vector with all the categories considered public green areas. If it is not provided, the function uses the categories from city_land_uses where the attribute public is TRUE. The argument residence_col indicates the variable of the urban representation (x) that must be used to identify the residences. Subsequently, residences indicates which categories of the ones contained by the variable passed to residence_col must be considered. The min_area argument can be used to exclude smaller areas than the value passed to the function (the threshold mentioned above).

If percent_out is set to TRUE, the function returns the percentage of houses that are further than max_dist argument from their closest public green area (excluding areas smaller than min_area). The default values for min_area and max_dist follow the recommendations of the World Health Organization, who recommended that all residences should be closer than 300 meters from a public green area larger than 0.5 ha.

Finally, if verbose argument is set to TRUE, a vector with all distances from residences to green areas (larger than min_area) is returned.

Code snippet 3: Function and arguments to calculate green accessibility

green_distance(
  x,                                             # The urban representation
  green_cat = NULL,                           # The land uses considered urban green
  residence_col = "land_use_verbose",      # The variable than contains information of what is a residence
  residences = "Residence",                 # The categories of former variable considered residences
  min_area = 5000,                           # Smaller areas are not included in the calculations
  percent_out = FALSE,                      # Should the function return a percentage of residences out
  max_dist = 300,                            # Which is the distaince to consider that a residence is out?
  verbose = FALSE                            # Should return a summary of distance or all values?
)

Nitrogen dioxide sequestration Nitrogen dioxide is a good proxy of overall air quality (Mayer, 1999) and one of the most concerning issues in cities, with important consequences on respiratory diseases and lung cancer (Kampa & Castanas, 2008). This indicator calculates the amount of NO2 sequestered by urban green and urban agriculture solutions (in g/s).

NO2seq=∑i=1Nai×capi1000

where ai is the area (in m2) of the element i; and capi is the capacity of element i to sequester NO2 (in µg·s-1m-2).

The function to estimate the NO2 sequestered is no2_seq (code snippet 4). It has only two arguments; the urban representation (x) and a data.frame with four columns:

  • land_uses: Column with the land use.

  • no2_seq1: The low range of NO2 sequestration of each function (in µg·s-1m-2).

  • no2_seq2: The high range of NO2 sequestration of each function (in µg·s-1m-2).

  • pGreen: The proportion of green surface in each function.

When the argument is NULL (default), the function uses the city_land_uses dataset provided with the package that contains NO2 sequester capacity of different types of urban green.

The capacity (capi in the previous equation) of each element is randomized within the range provided by no2_seq1 and no2_seq2. As well the area of each element is multiplied by pGreen. In urban agriculture solutions, the attribute edible_area overrides the more general pGreen.

Code snippet 4: Function and arguments to calculate NO2 sequestration

no2_seq(x,                     # The urban representation
         green_df = NULL)     # The data.frame with the NO2 sequestration capacity of each land use.

Jobs created and volunteers involved When the urban agriculture solutions are community solutions they need volunteers to be involved. On the other hand, when they are for commercial purposes, they are supposed to create jobs. Therefore, two indicators are proposed to account for the hours of work in the ECS. One indicator relates to volunteers’ time and the other one relates to time spent by new workers (jobs created). Both indicators use the same equation:

jobs|volunteers=∑i=1Nai×k

where ai is the area in m2 used to grow plants (edible_area) in the element i; and k is the number of jobs or volunteers by m2. In both functions, k is sampled from a random uniform distribution within the specified range. Then, a Monte Carlo simulation of 1,000 iterations is executed to estimate the confidence interval. The default values were based on two sources, an empirical study (CoDyre et al., 2015) and the FoodMetres project.

The functions to calculate these indicators are edible_jobs and edible_volunteers respectively (code snippet 5). They share the same arguments, expect for jobs and volunteers, which is the value of k in the previous equation. As usual, the first argument is the urban representation (x), edible is the land uses in x that are urban agriculture solutions (if NULL, city_land_uses is used as default), the attribute of x defining the area used to grow plants is area_col, the confidence interval is defined in interval, and if verbose is set to TRUE, instead of the confidence interval, the function returns a vector of length 1,000 with all the results of the Monte Carlo simulation.

Code snippet 5: Function and arguments to calculate number of jobs created and volunteers involved in urban agriculture.

edible_jobs(
  x,                                    # The urban representation
  jobs = c(0.000163, 0.022),         # The k parameter
  edible = NULL,                      # The land uses that are urban agriculture
  area_col = "edible_area",          # The variable containing the surface dedicated to grow plants
  interval = 0.95,                    # The confidence interval returned by the function
  verbose = FALSE                     # Should return all values or a summary?
)

edible_volunteers(
  x,                                    # The urban representation
  volunteers = c(0.00163, 0.22),    # The k parameter
  edible = NULL,                      # The land uses that are urban agriculture
  area_col = "edible_area",          # The variable containing the surface dedicated to grow plants
  interval = 0.95,                    # The confidence interval returned by the function
  verbose = FALSE                     # Should return all values or a summary?
)

Green per capita We propose an indicator to estimate green per capita at neighborhood level and at city level, including public and private gardens to account for environmental justice (Kabisch & Haase, 2014). At the neighborhood level a ratio between the most and least green neighborhoods is calculated, with higher values meaning a major difference between neighborhoods and less spatial justice. Moreover, since wealthier areas tend to have more private gardens (Farahani et al., 2018), these can be included in the account of green per capita to not underestimate green per capita in those neighborhoods.

The function to calculate this indicator is green_capita (code snippet 6). Along with the urban representation (x). As in other functions, the green_categories argument in the function is a list of the categories to be considered as green areas. To calculate the green per capita in the overall city, the user must provide the number of inhabitants in inhabitants. At a city level, the function returns the average amount of green per capita in the city (in m2/inhabitant). Likewise there are two options to calculate green per capita at a neighbourhood level. The urban representation can contain two variables indicating the name of the neighbourhood and the inhabitants (specified in name_col and inh_col arguments respectively). Or the user can provide a GIS layer with the neighbourhoods’ boundaries and their attributes.

Furthermore, when the private argument is set to TRUE, the private gardens are also considered. Alternatively, the user can provide a list of elements to be considered as private green areas (e.g. parks, urban gardens,. . . ). When the argument verbose is set to TRUE, the function returns the green per capita in each neighbourhood instead of the ratio between the most and least green ones. Finally, the argument min_inh is to exclude neighbourhoods whose number of inhabitants is under a threshold to avoid the bias in green per capita due to unpopulated neighbourhoods (e.g. industrial districts).

Code snippet 6: Function and arguments to calculate green per capita.

green_capita(
  x,                            # The urban representation
  green_categories = NULL,   # The categories considered as urban green
  inhabitants = NULL,         # The number of inhabitants in the city
  neighbourhoods = NULL,      # The spatial representation of neighborhoods
  name_col = NULL,             # The variable that contains de name of the neighborhoods
  inh_col = NULL,              # The variable that contains the inhabitants of the neighborhoods
  private = FALSE,             # Should private green be considered?
  verbose = FALSE,             # Should return all the information or just the ratio?
  min_inh = 0                   # Neighborhoods with less hanbitants are excluded
)

Food production Although many authors stated that the main goal of urban agriculture is not to produce food (Säumel et al., 2019; Tornaghi, 2012), food production is undoubtedly an important component of urban gardens (Furness & Gallaher, 2018; Steel, 2008) and the most frequent output modeled at a city scale (Grafius et al., 2020; Grewal & Grewal, 2012). The food production is measured in terms of productivity (kg/m2):

Foodproduction=∑i=1Nykai

where yk is the yield (in kg/m2) of the category k of urban garden; and ai is the area of urban garden i in m2. By default, the value of y is randomized using a random uniform distribution within the range defined by food1 and food2 values in city_land_uses, which are the minimum and maximum yield values found in the literature for each category of urban garden. The function computes a Monte Carlo simulation of 1,000 iterations to calculate the confidence interval.

The function that calculates the food production is food_production (code snippet 7). It takes the urban representation (x) as the first argument. If the second argument edible_df is NULL, the function uses the values from city_land_uses as specified above. Otherwise, the user can provide its own values as a data.frame with three columns:

  • land_uses: specifying the category of urban agriculture, it should match the categories from x.

  • food1 and food2 specifies the range of the random uniform distribution to randomize yield.

The argument area_col points to the variable of x that determines the area dedicated to grow plants in each urban garden. If NULL, the total area of each element is used instead. The number passed to interval defines which confidence interval of the food production must be returned by the function. However, if verbose is set to TRUE, the function returns a vector of length 1,000 with the results of each iteration of the Monte Carlo simulation.

Code snippet 7: Function and arguments to estimate food production

food_production(
  x,                           # The urban representation
  edible_df = NULL,          # Dataframe containing information on yields
  area_col = "edible_area", # Variable of x with surface
  interval = 0.95,           # Confidence interval returned by the function
  verbose = FALSE            # Should return all the values or just the confidence interval?
 )

Scenarios of urban agriculture. The ediblecity package also provides the user with a function to create new scenarios based on the urban representation and a predefined set of urban agriculture solutions (Table 3) based on where they are located (private gardens, plots on ground or rooftops) and their purpose (private, community or commercial). The function returns a spatial representation of the new scenario (sf object) with the same structure of the urban representation.

Table 3. Elements created in new scenarios.

Urban agriculture solutionsLocationPurpose
Edible private gardenPrivate gardensPrivate
Community gardenPlots on groundCommunity
Commercial gardenPlots on groundCommunity
Rooftop gardenRooftopsCommercial
Hydroponic rooftopRooftopsCommercial

The location of new urban agriculture elements is randomized among all locations that fulfill the requirements of minimum area for that element. However, this is not the case for commercial gardens, they are settled in the larger available locations, assuming that commercial initiatives have the power to acquire the best spots.

The function to create a new scenario is called set_scenario (code snippet 8). It requires many arguments but most of them have default values to facilitate its use. The function needs the urban representation (x). Then three arguments (pGardens, pVacant, pRooftop) control the proportion of new elements that must be created. The next three arguments (edible_area_*) control the proportion of the area of the new elements that is dedicated to grow plants (edible_area). The edible_area of each new elements is randomized within the range provided in the arguments. The next trio of arguments (min_area_*) specify the minimal area required to create new elements. If there are not enough elements larger than min_area_* to fulfill the first arguments, a message is displayed to inform the user (unless quiet argument is set to TRUE). Another three arguments (*_from) control which elements can be converted from the urban representation to create new urban agriculture solutions. The argument pcommercial controls the percentage of plots on ground and rooftop that should have commercial purposes instead of community. This does not affect private gardens since they are assumed to be for personal use. Finally, area_field specifies which attribute of x must be used as the area of the elements. By default, it is am attribute called flat_area that measures the area with an slope lower than 5⍛ (in city_example).

Code snippet 8: Function and arguments to create new scenarios.

 set_scenario(
   x,                                              # The urban representation
   pGardens = 1,                                  # Proportion of private edible gardens
   pVacant = 1,                                   # Proportion of vacant plots converted to gardens on ground
   pRooftop = 1,                                 # Proportion of rooftops converted to rooftop gardens
   edible_area_garden = c(0.02, 0.3),         # Proportion of surface dedicated to grow plants in private gardens
   edible_area_vacant = c(0.52, 0.75),        # And in gardens on ground
   edible_area_rooftop = c(0.6, 0.62),        # And in rooftop gardens
   min_area_garden = 10,                       # Exclude smaller private gardens
   min_area_vacant = 100,                       # Exclude smaller vacant plots
   min_area_rooftop = 100,                     # Exclude smaller rooftops
   private_gardens_from = "Normal garden",  # Land uses to be converted to private edible gardens
   vacant_from = "Vacant",                     # Land uses to be converted to gardens on ground
   rooftop_from = "Rooftop",                    # Land uses to be converted to rooftop gardens
   pCommercial = 0,                            # Proportion of commercial gardens vs community gardens
   area_field = "flat_area",                   # Variable of x containing available surface in each element
   quiet = FALSE                               # Should the function raise warnings?
)

Operation

The ediblecity package is compatible with versions of R higher than 2.10. However, it was created using version 4.2.1. Code snippet 9 shows how to install the last development version, available in r-universe.

Code snippet 9: Code to install the last development version of the package

# install.packages("devtools") # if not yet installed
install.packages("ediblecity", repos = "jospueyo.r-universe.dev")

Once the package is installed, it works as any R package. It can be attached to the namespace using library(ediblecity) or preceding the functions with ediblecity::. To check the documentation of the package and its functions, type help(package="ediblecity") in the R console.

Limitations

As all abstractions of reality, the equations and algorithms of the ediblecity package present some limitations. One limitation is the use of GIS layers to create scenarios and estimate indicators, which is intrinsically in two dimensions, and sometimes 2.5 dimensions, since we consider the height of buildings. This prevents from considering other urban agriculture solutions that are relevant such as vertical farming. To consider vertical solutions, the ediblecity package should include 3D calculations.

Another limitation is the subset of indicators chosen; this is, as we said, a choice. Other indicators might be chosen instead or added to the current subset. Hopefully, the ediblecity package will be well received by the community of R scientists and other developers will add new indicators to fulfill their own needs. Indeed, this is one of the main advantages of open-source software.

Likewise, we opted to only choose indicators to estimate the benefits of urban agriculture. However, urban agriculture has also some drawbacks that could be measured. Certainly, various research studies have drawn attention to a range of concerns within the realm of urban agriculture (UA). For instance, Graefe et al. (2019) emphasized the issue of heavy metal presence in cultivated plants, while Perrin et al. (2015) discussed the improper use of pesticides and fertilizers. These factors not only pose threats to both the environment and human well-being but also bring into focus the need for sustainable practices. In a similar vein, (Whittinghill et al., 2016) shed light on the dual nature of rooftop gardens. While they are effective in mitigating runoff, they can also contribute to nutrient runoff, especially when compared to extensive green roofs. This has implications for the quality of runoff water, underscoring the complexity of UA's environmental impacts. Moreover, beyond the potential environmental and health consequences, UA can also give rise to adverse social effects, as highlighted by Hawes et al. (2022). These repercussions, like the phenomenon of green gentrification, deserve careful consideration in the context of urban agriculture development.

Use cases

To replicate this section, apart from the ediblecity package, you will need to load the following packages in your R namespace using the function library(<package>):

Use cases

Create scenarios of urban agriculture

To our understanding, the most important use case of the ediblecity package is to compare scenarios. To illustrate this, we created two scenarios and compared them with the original city_example (Table 4). The package has been designed to work well with the tidyverse framework in R (Wickham et al., 2019), especially, with the map_* family in the purrr package (Henry & Wickham, 2022a). Therefore, we first create the two scenarios and save them in a list along with the original urban representation, which we called s0 (Code snippet 10). The scenario s1 will convert the 25% of elements to urban agriculture solutions while the scenario s2 will convert the 100%. Half of gardens in vacant plots, streets and rooftop will have commercial purposes.

Table 4. Number of agriculture solutions in each scenario and their surfaces (in squared meters).

land_uses0 ns1 ns2 ns0 areas1 areas2 area
Community garden11956320702414950
Commercial garden0195602828446769
Edible private garden011344201359955587
Hydroponic rooftop07616405836087090
Rooftop garden07516401421722485

Code snippet 10: Code to create the scenarios.

# Create new scenarios
scenarios <- map(c(0.25, 1), ~set_scenario(city_example,
                                 pGardens = .x,
                                 pVacant = .x,
                                 pRooftop = .x,
                                 private_gardens_from = "Normal garden",
                                 vacant_from = c("Vacant", "Streets"),
                                 rooftop_from = "Rooftop",
                                 pCommercial = 0.5))
#> Only 442 private gardens out of 453 assumed satisfy the 'min_area_garden'
#> Only 111 vacant plots out of 149 assumed satisfy the 'min_area_vacant'
#> Only 328 rooftops out of 604 assumed satisfy the 'min_area_rooftop'

# Add city_example as s0
scenarios[[3]] <- city_example

# Name the scenarios
names(scenarios) <- c("s1", "s2", "s0")
scenarios <- scenarios[order(names(scenarios))]

Calculate indicators and compare scenarios

In this section, we calculate the indicators for each scenario and create tables or plots as illustration of how the results can be used.

Code snippet 11: Code to create a table with the result of urban heat island in all three scenarios.

# We use the SVF object that is provided for the city_example in the package
map_dfr(scenarios, UHI, SVF = ediblecity::SVF, .id = "Scenario") |>
  kable(caption = "Summary statistics of urban heat island effect in each scenario (in ºC)")

As expected the second scenario (s2) has the lowest values for urban heat island, but not too far from the scenario s1 (Table 5). Both present a reduction of approximated 50% in average urban heat island regarding the base scenario. The absolute reduction in degrees can also be compared to the average temperature in summer in the study area. In our case study, July 2022 had an average temperature of 28°C. The reduction caused by UA would suppose a reduction of 3.5%. We can also generate a raster with the urban heat island for each scenario, like in Figure 2

Table 5. Summary statistics of urban heat island effect in each scenario (in ⍛C).

ScenarioMin.1st Qu.MedianMean3rd Qu.Max.
s001.251.601.492.12.7
s100.641.251.181.92.7
s200.530.970.991.32.6
37edffb8-6b20-40a9-b5be-309b2f37c984_figure2.gif

Figure 2. Raster returned by the UHI function when return_raster is set to TRUE.

Code snippet 12: Code to calculate the runoff prevention in each scenario.

map_dfr(scenarios, runoff_prev, .id="scenario") |>
  kable(caption = "Runoff (mm), total rainfall (mˆ3ˆ) and rainwater harvested in each scenario (mˆ3ˆ)")

The total rainfall presented the same value in all scenarios because we used the same rain event and all scenarios represent the same total area (Table 6). Moreover, although there was an important reduction of runoff and an increase in rainwater harvested regarding the base scenario, there was no improvement from scenario 1 to scenario 2. As shown in Code snippet 12, the rainwater harvested was larger in scenario 1. This is explained because the algorithm uses as catchment areas all adjacent upper areas that are not used for urban agriculture. Hence, as rooftop converted to urban agriculture increases, the availability of catchment areas decrease. The infiltration rates also increase because rooftop gardens retain water but this is not enough to compensate the reduction in harvesting. However, harvested water has also some benefits, mainly water reuse. For instance, Girona’s inhabitants have an average consumption of 134 litres /day. This multiplied by the inhabitants of Sant Narcís gives a total consumption of 847 m3/day. Hence, the water harvested in scenario 1 could provide all the water in the neighbourhood during 2 days and a half.

Table 6. Runoff (mm), total rainfall (m3) and rainwater harvested in each scenario (m3).

Scenariorunoffrainfallrainharvest
s0381081691188
s1351081692040
s2351081691760

Code snippet 13: Code to generate a boxplot of distances to public green areas (result show in Figure 3).

map_dfc(scenarios, green_distance, min_area = 100, verbose = TRUE) |>
  pivot_longer(everything()) |>
  ggplot(aes(x=name, y=as.numeric(value), fill=name))+
  geom_boxplot(show.legend = FALSE)+
  labs(fill="Scenario", x= "Scenario", y="Distance from residences \nto public green areas (m)")
37edffb8-6b20-40a9-b5be-309b2f37c984_figure3.gif

Figure 3. Comparison among scenarios of the distances to each residences to its closest public green area.

This indicator can be used to explore the fullfilment of WHO recommendations, which recommend that all citizens should have a green area larger than 0,5 ha closer than 300 metres (WHO, 2017). This can be achieved by adjusting the argument min_area used to calculate the indicator that filters all the green areas smaller than the value provided to the argument.

Code snippet 14: Estimation of NO2 sequestration in all three scenarios

map_dfr(scenarios, no2_seq, .id="Scenario") |>
  kable(caption = "Sequestration of nitrogen dioxide in each scenario")

Regarding the capacity to absorb NO2, we see a significant improvement from base scenario to scenario 1 but not as larger from scenario 1 to scenario 2 (Table 7). Considering the car emissions limitation imposed by the Euro 6 standard and assuming that cars drive at 50 km/h in the city, The sequestration of scenario 2 is approximately equivalent to neutralizing emissions from 130 cars (1.04 gr/s/car).

Table 7. Sequestration of nitrogen dioxide in each scenario.

Scenariogr/s
s0102
s1107
s2110

In the Code snippet 15, there is an example to calculate jobs as well as volunteers in the different scenarios.

Code snippet 15: Code to estimate jobs and volunteers in each scenario.

jobs <- scenarios |>
  map_dfc(edible_jobs, verbose = TRUE) |>
  pivot_longer(everything(), values_to = "Jobs")

volunteers <- scenarios |>
  map_dfc(edible_volunteers, verbose = TRUE) |>
  pivot_longer(everything(), values_to = "Volunteers")

bind_cols(jobs, volunteers["Volunteers"]) |>
   pivot_longer(-name, names_to = "Indicator") |>
   ggplot(aes(x=Indicator, y=value, fill=name))+
   geom_boxplot()+
   labs(y = "People", fill="Scenario")

As expected, the base scenario presented very low values; it created 0 jobs since there were no commercial garden and a median of 18.1 volunteers involved in one community garden. The number of jobs and volunteers also increased from scenario 1 to scenario 2 as well as the uncertainty related to the numbers (Figure 4). The number of jobs and volunteers can be compared to the population in the neighbourhood. In that case, using median values, the jobs of scenario 2 represents 30% of the population while the volunteers the 40%. We must note, that the scenario 2 is converting all the available streets and rooftops to urban gardens, and so the number may feel a bit overestimated.

37edffb8-6b20-40a9-b5be-309b2f37c984_figure4.gif

Figure 4. Comparison of jobs created and volunteers involved in each scenario.

Below, we calculated the green per capita in each neighborhoods (code snippet 16). To do so, we use another spatial data set provided by the ediblecity package (neighbourhoods_example) which contains the neighborhoods of city_example along with the inhabitants in each neighborhood.

Code snippet 16: Code to calculate the green per capita in each neighborhood

scenarios |>
  map_dfr(green_capita,
           neighbourhoods = neighbourhoods_example,
           inh_col = "inhabitants",
           name_col = "name",
           private = TRUE,
           verbose = TRUE,
           .id = "scenarios") |>
ggplot(aes(x=name, y=green_capita, fill=scenarios))+
geom_col(position = position_dodge(), color = "black")+
labs(x="Neighborhoods", y=bquote(mˆ2/person), fill="Scenario")

The difference between both neighborhoods (Figure 5) is due to their urban origin. Sant Narcís nord was designed like a city garden while Sant Narcís sud is mainly composed of apartments. The interesting issue is that the improvement across scenarios is larger in Sant Narcís nord that in Sant Narcís sud, evidencing that an increase in urban agriculture is not enough to achieve environmental justice unless it is ideologically planned (Jennings et al., 2012). However, remarkably, Sant Narcís sud increased from 6.6 to 9.4 m2/capita from base scenario to scenario 1, surpassing the standard of 9 m2/capita.

37edffb8-6b20-40a9-b5be-309b2f37c984_figure5.gif

Figure 5. Comparison of green per capita in both neighbourhoods of Sant Narcís.

The last, but not least, indicator provided by the ediblecity package is the food production. The food production is assumed to be higher in gardens for commercial purposes than in community gardens, the goal of which is not to maximize the production. This is especially the case of rooftops, since commercial rooftop gardens are assumed to use hydroponic technology while community rooftop gardens are assumed to use raised beds, following the study of Caputo, Rumble, and Schaefer (2020).

Code snippet 17: Code to get confidence intervals of food production in Tm/year.

scenarios |>
  map_dfr(food_production, .id = "Scenario") |>
  mutate(across(where(is.numeric), ~ .x/1000)) |>
  kable(caption = "Food production in Tm/year in each scenario")

Although the medians are clearly different, we cannot state that food production is bigger in scenario 2 than in scenario 1 with a 95% of confidence (i.e. p-value > 0.05 in differences between s1 and s2) (Table 8). Taking the most optimistic scenario (s2 at quantile 95%) and considering the value per capita, the urban agriculture in our example could produce 191.94 kg/year/person. The daily intake of fruits and vegetables recommended by the FAO is 200 gr/person, i.e. 73 kg/person/year (FAO & WHO, 2004). Therefore, our optimistic estimation would provide 2.63 times the neighborhood’s needs in fruits and vegetables. However, it would require (taking also the higher interval) 3,510 people working in commercial gardens and 4,829 volunteers involved in community gardens, which is 1.32 times the inhabitants of the neighborhood.

Table 8. Food production in Tm/year in each scenario.

Scenario5%50%95%
s00.050.190.33
s1457.31610.77780.81
s2720.96965.541215.50

Disclaimer

Since the scenarios and the indicators have some stochastic parameters, the ideal procedure would be to integrate the creation of the scenarios and the estimation of indicators in a Monte Carlo simulation to get the confidence intervals for each combination of scenario and indicator. However, we rather kept things simple to better illustrate how to use the functions provided by the package.

Conclusions

In this paper, we presented the ediblecity package: An R package to model and estimate the benefits of urban agriculture. The package is ready to be used by R users with a basic level. It can be used to estimate the benefits of real cases as well as to simulate scenarios. In both cases, 8 indicators are calculated. In the example illustrated in this paper, the uncertainty is captured using stochastic parameters. Moreover, the users are able to provide their own ranges in case they have more accurate data for the case study at stake. With more accurate data, the uncertainty can be easily reduced by changing the arguments of the functions. Likewise, some assumptions of the models can be overridden with truly statements.

The ediblecity package is open-source software under MIT license. This allows other R developers to contribute to the package providing new functionalities or improving the existing ones. Therefore, an open-source software is always a work-in-progress.

Data availability

Underlying data

Zenodo: icra/ediblecity: To zenodo, https://doi.org/10.5281/zenodo.7913285

Data are available under the terms of the Creative Commons Attribution 4.0 International license (CC-BY 4.0).

Software availability

Authors contributions

JPR, JC and LC contributed to conceptualization, methodology and writing - review & editing. JPR contributed to data curation, formal analysis, software, validation, visualization and writing - original draft preparation. JC and LC contributed to funding acquisition, project administration, resources and supervision.

Acknowledgements

We want to aknowledge the R community for being so supportive and friendly in StackOverflow, but also in Mastodon under the hashtag #Rstats. Also, we thank Posit (former RStudio) for all the tools that make the life easier to R developers. Likewise, we want to thank all R developers that altruistically spend their time in building open-source packages.

References

  •  Artmann M, Sartison K: The role of urban agriculture as a nature-based solution: A review for developing a systemic assessment framework. Sustainability. 2018; 10(6): 1937. Publisher Full Text
  •  Bache SM, Wickham H: Magrittr: A Forward-Pipe Operator for r. 2022. Reference Source
  •  Barthel S, Parker J, Ernstson H: Food and Green Space in Cities: A Resilience Lens on Gardens and Urban Environmental Movements. Urban Studies. 2015; 52(7): 1321–38. Publisher Full Text
  •  Caputo S, Rumble H, Schaefer M: "I like to get my hands stuck in the soil": A pilot study in the acceptance of soil-less methods of cultivation in community gardens. J Clean Prod. 2020; 258: 120585. Publisher Full Text
  •  Clinton N, Stuhlmacher M, Miles A, et al.: A Global Geospatial Ecosystem Services Estimate of Urban Agriculture. Earths Future. 2018; 6(1): 40–60. Publisher Full Text
  •  CoDyre M, Fraser EDG, Landman K: How does your garden grow? An empirical evaluation of the costs and potential of urban gardening. Urban For Urban Green. 2015; 14(1): 72–79. Publisher Full Text
  •  Conrad O: Module Sky View Factor. SAGA, 2008. Reference Source
  •  Cronshey RG, Roberts RT, Miller N: Urban Hydrology for Small Watersheds (Tr-55 Rev). Edited by USDA Natural Resources Conservation Services, 1985. Reference Source
  •  Dumitru A, Wendling L: Evaluating the Impact of Nature-based Solutions: A Handbook for Practitioners. European Commission - Directorate-General for Research and Innovation. 2021. Reference Source
  •  FAO and WHO: Fruit and Vegetables for Health Fruit and Vegetables. Kobe, 2004. Reference Source
  •  Farahani LM, Maller C, Phelan K: Private Gardens as Urban Greenspaces: Can they compensate for Poor Greenspace Access in lower socioeconomic neighbourhoods? Landsc Online. 2018; 59: 1–18. Publisher Full Text
  •  Furness WW, Gallaher CM: Food access, food security and community gardens in Rockford, IL. Local Environment. 2018; 23(4): 414–30. Publisher Full Text
  •  Gittleman M, Farmer CJQ, Kremer P, et al.: Estimating stormwater runoff for community gardens in New York City. Urban Ecosyst. 2017; 20(1): 129–39. Publisher Full Text
  •  Gómez-Villarino MT, Ruiz-Garcia L: Adaptive design model for the integration of urban agriculture in the sustainable development of cities. A case study in northern Spain. Sustain Cities Soc. 2021; 65: 102595. Publisher Full Text
  •  Graefe S, Buerkert A, Schlecht E: Trends and gaps in scholarly literature on urban and peri-urban agriculture. Nutr Cycling Agroecosyst. 2019; 115(2): 143–158. Publisher Full Text
  •  Grafius DR, Edmondson JL, Norton BA, et al.: Estimating food production in an urban landscape. Sci Rep. 2020; 10(1): 5141. PubMed Abstract | Publisher Full Text | Free Full Text
  •  Grewal SS, Grewal PS: Can cities become self-reliant in food? Cities. 2012; 29(1): 1–11. Publisher Full Text
  •  Hawes JK, Gounaridis D, Newell JP: Does urban agriculture lead to gentrification? Landsc Urban Plan. 2022; 225: 104447. Publisher Full Text
  •  Henry L, Wickham H: purrr: Functional Programming Tools. 2022a. Reference Source
  •  Henry L, Wickham H: Rlang: Functions for Base Types and Core r and ’Tidyverse’ Features. 2022b. Reference Source
  •  Hsieh YH, Hsu JT, Lee TI: Estimating the potential of achieving self-reliance by rooftop gardening in Chiayi City, Taiwan. Int J Des Nat Ecodyn. 2017; 12(4): 448–57. Publisher Full Text
  •  Jennings V, Gaither CJ, Gragg RS: Promoting environmental justice through urban green space access: A synopsis. Environmental Justice. 2012; 5(1): 1–7. Publisher Full Text
  •  Kabisch N, Haase D: Green justice or just green? Provision of urban green spaces in Berlin, Germany. Landsc Urban Plan. 2014; 122: 129–39. Publisher Full Text
  •  Kampa M, Castanas E: Human health effects of air pollution. Environ Pollut. 2008; 151(2): 362–67. PubMed Abstract | Publisher Full Text
  •  Langemeyer J, Madrid-Lopez C, Beltran AM, et al.: Urban agriculture — A necessary pathway towards urban resilience and global sustainability? Landsc Urban Plan. 2021a; 210: 104055. Publisher Full Text
  •  Langemeyer J, Madrid-Lopez C, Beltran AM, et al.: Urban agriculture — A necessary pathway towards urban resilience and global sustainability? Landsc Urban Plan. Elsevier B.V., 2021b; 210: 104055. Publisher Full Text
  •  Lin BB, Philpott SM, Jha S: The future of urban agriculture and biodiversity-ecosystem services: Challenges and next steps. Basic Appl Ecol. 2015; 16(3): 189–201. Publisher Full Text
  •  Lupia F, Baiocchi V, Lelo K, et al.: Exploring Rooftop Rainwater Harvesting Potential for Food Production in Urban Areas. Agriculture. 2017; 7(6): 46. Publisher Full Text
  •  MacRae R, Gallant E, Patel S, et al.: Could Toronto provide 10% of its fresh vegetable requirements from within its own boundaries? Matching consumption requirements with growing spaces. J Agric Food Syst Community Dev. 2010; 1(2): 105–27. Publisher Full Text
  •  Mayer H: Air pollution in cities. Atmos Environ. 1999; 33(24–25): 4029–37. Publisher Full Text
  •  Pebesma E: Simple Features for R: Standardized Support for Spatial Vector Data. The R Journal. 2018a; 10(1): 439–46. Publisher Full Text
  •  Pebesma E: Simple Features for R: Standardized Support for Spatial Vector Data. The R Journal. 2018b; 10(1): 439–46. Publisher Full Text
  •  Pebesma E: stars: Spatiotemporal Arrays, Raster and Vector Data Cubes. 2021. Reference Source
  •  Pebesma E: stars: Spatiotemporal Arrays, Raster and Vector Data Cubes. 2022.
  •  Perrin A, Basset-Mens C, Huat J, et al.: High environmental risk and low yield of urban tomato gardens in Benin. Agron Sustain Dev. 2015; 35(1): 305–315. Publisher Full Text
  •  R Core Team: R: A Language and Environment for Statistical Computing. Vienna, Austria: R Foundation for Statistical Computing, 2022. Reference Source
  •  Richardson JJ, Moskal LM: Urban food crop production capacity and competition with the urban forest. Urban For. Urban Green. 2016; 15: 58–64. Publisher Full Text
  •  Säumel I, Reddy SE, Wachtel T: Edible city solutions-one step further to foster social resilience through enhanced socio-cultural ecosystem services in cities. Sustainability. (Switzerland), 2019; 11(4): 972. Publisher Full Text
  •  Shukla PR, Skea J, Buendia EC, et al.: IPCC, 2019: Climate Change and Land: an IPCC special report on climate change, desertification, land degradation, sustainable land management, food security, and greenhouse gas fluxes in terrestrial ecosystems. IPCC, 2019. Reference Source
  •  Soga M, Cox DTC, Yamaura YY, et al.: Health benefits of urban allotment gardening: Improved physical and psychological well-being and social integration. Int J Environ Res Public Health. 2017; 14(1): 71. PubMed Abstract | Publisher Full Text | Free Full Text
  •  Steel C: Hungry city: how food shapes our lives. London: Chatto & Windus, 2008; 383. Reference Source
  •  Theeuwes NE, Steeneveld GJ, Ronda RJ, et al.: A diagnostic equation for the daily maximum urban heat island effect for cities in northwestern Europe. Int J Climatol. 2017; 37(1): 443–454. Publisher Full Text
  •  Tornaghi C: Public space, urban agriculture and the grassroots creation of new commons: lessons and challenges for policy makers. In: Sustainable Food Planning: Evolving Theory and Practice. edited by A. Viljoen and J. S. C. Wiskerke, Wageningen Academic Publishers, 2012; 349–364. Publisher Full Text
  •  Whittinghill LJ, Hsueh D, Culligan P, et al.: Stormwater performance of a full scale rooftop farm: Runoff water quality. Ecol Eng. 2016; 91: 195–206. Publisher Full Text
  •  WHO: Urban green spaces: A brief for action. Regional Office For Europe. 2017; 24. Reference Source
  •  Wickham H: ggplot2: Elegant Graphics for Data Analysis. Springer-Verlag New York, 2016. Reference Source
  •  Wickham H, Averick M, Bryan J, et al.: Welcome to the {tidyverse}. J Open Source Softw. 2019; 4(43): 1686. Publisher Full Text
  •  Wickham H, Bryan J: R Packages (2e). O’REILLY. 2022. Reference Source
  •  Wickham H, Danenberg P, Csárdi G, et al.: Roxygen2: In-Line Documentation for r. 2022a. Reference Source
  •  Wickham H, François R, Henry L, et al.: dplyr: A Grammar of Data Manipulation. 2023a. Reference Source
  •  Wickham H, Hester J, Chang W, et al.: Devtools: Tools to Make Developing r Packages Easier. 2022b. Reference Source
  •  Wickham H, Henry L: purrr: Functional Programming Tools. 2023. Reference Source
  •  Wickham H, Vaughan D, Girlich M: tidyr: Tidy Messy Data. 2023b. Reference Source
  •  Xie Y: knitr: A General-Purpose Package for Dynamic Report Generation in R. 2023. Reference Source