Feature Property Charts

Chart data in a FeatureCollection using one of the methods starting with ui.Chart.feature. Unlike images, features don’t necessarily have a timestamp, so the feature properties to chart must be specified. Use ui.Chart.feature.byProperty() to plot each feature as a different series, with properties on the X-axis. Use ui.Chart.feature.byFeature() to plot specified properties, with features on the X-axis. The following example illustrates the difference between byProperty() and byFeature() by plotting US states with extreme temperatures in different months:

// Load a table of average seasonal temperatures in U.S. cities.
// Import US state boundaries.
var states = ee.FeatureCollection('TIGER/2018/States');

// Import temperature normals and convert month features to bands.
var normClim = ee.ImageCollection('OREGONSTATE/PRISM/Norm81m')
  .select(['tmean'])
  .toBands();

// Calculate mean monthly temperature per state.
states = normClim.reduceRegions({
  collection: states,
  reducer: ee.Reducer.mean(),
  scale: 5e4})
  .filter(ee.Filter.notNull(['01_tmean']));

// Calculate Jan to Jul temperature difference per state and set as a property.
states = states.map(function(state) {
  var julyTemp = ee.Number(state.get('06_tmean'));
  var janTemp = ee.Number(state.get('01_tmean'));
  return state.set('seasonal_delta', julyTemp.subtract(janTemp));
});

// Select the extreme states.
var extremeStates =
  states.limit(1, '01_tmean')                 // Coldest.
  .merge(states.limit(1, '07_tmean', false))  // Hottest.
  .merge(states.limit(1, 'seasonal_delta'));  // Least variation.

// Define properties to chart.
var months = {
  '01_tmean': 1,
  '04_tmean': 4,
  '07_tmean': 7,
  '10_tmean': 10
};

// Prepare the chart.
var chart1 =
  ui.Chart.feature.byProperty(extremeStates, months, 'NAME')
    .setChartType('ScatterChart')
    .setOptions({
      title: 'Average Temperatures in U.S. States',
      hAxis: {
        title: 'Month',
        ticks: [{v: months['01_tmean'], f: 'January'},
                {v: months['04_tmean'], f: 'April'},
                {v: months['07_tmean'], f: 'July'},
                {v: months['10_tmean'], f: 'October'}]
      },
      vAxis: {
        title: 'Temperature (Celsius)'
      },
      lineWidth: 1,
      pointSize: 3
    });


// Make a chart by feature.
var chart2 =
  ui.Chart.feature.byFeature(extremeStates, 'NAME', Object.keys(months))
    .setChartType('ColumnChart')
    .setSeriesNames(['Jan', 'Apr', 'Jul', 'Oct'])
    .setOptions({
      title: 'Average Monthly Temperatures, by State',
      hAxis: {title: 'State'},
      vAxis: {title: 'Temperature (Celsius)'}
    });

// Print the charts.
print(chart1, chart2);

The first part of this example finds the most extreme states in terms of average summer or winter temperature and seasonal range. Then the script plots the most extreme states in each category, either byProperty() or byFeature(). The output should look like Figure 1. The top plot in Figure 1 is the FeatureCollection charted by property, where the properties are arranged on the X-axis using the months dictionary. The bottom plot arranges the features on the X-axis, plotting each property as a different series.

ui.Chart.feature.by_
Figure 1. Charts of a FeatureCollection by property (top) and by feature (bottom).