I want to create a correlation chart between LST and NDBI for an area in Google Earth Engine (GEE). I have already created separate charts for both of these and now I need to know the correlation coefficient between the two.

Link to my Code: https://code.earthengine.google.com/f645e5e58586b9cef5da15bacf65e25c

I used the following piece of code to create the correlation chart, but there's an error popping up which says, "Error generating chart: Array: Parameter 'values' is required."

var yvalues = ee.Array(LST_ym.get('LST_Day_1km'));
var xvalues = ee.Array(NDBI_collection.get('B5'));
var chart = ui.Chart.array.values(yvalues, 0, xvalues)
.setSeriesNames(['LST_ym', 'NDBI_collection'])
  title: 'LST vs NDBI',
  hAxis: {'title': 'LST_ym'},
  vAxis: {'title': 'NDBI'},
  pointSize: 3,


1 Answer 1


You can far more easily plot both in the same graph. You have one image per year, so if you would add both the LST and the NDBI in the same collection with an image for every year, you can use chart.image.series for both.

Here is how to add them in a similar collection:

// make a mean image for every year and add the LST to the collection
var collection =  ee.ImageCollection.fromImages(year_list.map(function(ynz){
  // Landsat images
  var LST_year = LST.filter(ee.Filter.calendarRange(ynz, ynz, 'year')).mean();
  // Modis images
  var img = collection.filter(ee.Filter.calendarRange(ynz, ynz, 'year')).mean();
  var ndbi = img.normalizedDifference(['B5', 'B4']).rename('NDBI');
  // add a time band
  var time = ee.Image(ee.Date.fromYMD(ynz,1,1).millis()).divide(1e18).toFloat().rename('time');
  // return both and set date properties
  return ndbi.addBands([LST_year, time]).set('year', ynz).set('month', 1)
              .set('date', ee.Date.fromYMD(ynz,1,1))

Then add them to the chart on two different y axis, and set the trendlines to true in the graph. Moreover, you can show the R2 values and thus get their correlation directly inside that graph:

var LST_chart = ui.Chart.image.series({imageCollection: collection.select(['LST_Day_1km', 'NDBI']),
                                                  reducer: ee.Reducer.mean(),
                                                  scale: 1000
}).setOptions({title: "LST and NDBI MEAN", pointSize: 3,
    legend: {maxLines: 5, position: 'top'},
    series: {
          0: {targetAxisIndex: 0},
          1: {targetAxisIndex: 1}
        vAxes: {
          // Adds titles to each axis.
          0: {title: 'LST_Day ()'},
          1: {title: 'NDBI ()'}
    trendlines: {
        0: {
          type: 'linear',
          color: 'lightblue',
          lineWidth: 3,
          opacity: 0.7,
          showR2: true,
          visibleInLegend: true
        1: {
          type: 'linear',
          color: 'pink',
          lineWidth: 3,
          opacity: 0.7,
          showR2: true,
          visibleInLegend: true

Link code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.