ui.Chart.feature
モジュールには、Feature
オブジェクトと FeatureCollection
オブジェクトからグラフをレンダリングするための一連の関数が含まれています。関数を選択すると、グラフ内のデータの配置(X 軸と Y 軸の値を定義するもの、シリーズを定義するもの)が決まります。次の関数の説明と例を使用して、目的に最適な関数とグラフタイプを決定します。
グラフ関数
次のプロット図を視覚的なガイドとして使用して、各関数が特徴とそのプロパティをグラフに配置する方法(X 値、Y 値、シリーズを定義する要素)を理解します。
特徴は、選択したプロパティの値によって X 軸にプロットされます。シリーズは、値が Y 軸に沿ってプロットされるプロパティ名のリストによって定義されます。
特徴プロパティは名前で X 軸にプロットされ、指定されたプロパティの値は Y 軸にプロットされます。シリーズは、選択したプロパティの値でラベル付けされた特徴です。
特徴は、選択したプロパティの値によって X 軸にプロットされます。シリーズは、特定のプロパティの一意の値によって定義されます。Y 軸の位置は、特定のプロパティの値によって定義されます。
選択したプロパティの値の頻度ヒストグラム。
- X 軸: 選択したプロパティの値のヒストグラム バケット
- Y 軸: 各ヒストグラム バケットに該当する特徴量の頻度
データの例
次の例では、気候の標準値を記述するプロパティを持つ 3 つのエコリージョン特徴からなる FeatureCollection
を使用します。
サンプルデータの作成方法を確認する
コードエディタ(JavaScript)
// Define three representative ecoregions in the USA. var desert = ee.Feature( ee.Geometry.Rectangle(-109.21, 31.42, -108.3, 32.03), {label: 'Desert', value: 0}); var forest = ee.Feature( ee.Geometry.Rectangle(-122.73, 43.45, -122.28, 43.91), {label: 'Forest', value: 1}); var grassland = ee.Feature( ee.Geometry.Rectangle(-101.81, 41.7, -100.53, 42.51), {label: 'Grassland', value: 2}); // Combine features into a feature collection. var ecoregions = ee.FeatureCollection([desert, forest, grassland]); // Load PRISM climate normals image collection; convert images to bands. var normClim = ee.ImageCollection('OREGONSTATE/PRISM/Norm81m').toBands(); // Summarize climate normals for each ecoregion feature as a set or properties. ecoregions = normClim.reduceRegions( {collection: ecoregions, reducer: ee.Reducer.mean(), scale: 5e4}); // Add a property for whether January temperature is warm or not. ecoregions = ecoregions.map(function(ecoregion) { return ecoregion.set('warm', ee.Number(ecoregion.get('01_tmean')).gt(0)); });
ui.Chart.feature.byFeature
縦棒グラフ
特徴は X 軸に沿ってプロットされ、選択したプロパティの値でラベル付けされます。シリーズは、値が Y 軸に沿ってプロットされるプロパティ名のリストで定義された隣接する列で表されます。
コードエディタ(JavaScript)
// Import the example feature collection. var ecoregions = ee.FeatureCollection('projects/google/charts_feature_example'); // Define the chart and print it to the console. var chart = ui.Chart.feature .byFeature({ features: ecoregions.select('[0-9][0-9]_tmean|label'), xProperty: 'label', }) .setSeriesNames([ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]) .setChartType('ColumnChart') .setOptions({ title: 'Average Monthly Temperature by Ecoregion', hAxis: {title: 'Ecoregion', titleTextStyle: {italic: false, bold: true}}, vAxis: { title: 'Temperature (°C)', titleTextStyle: {italic: false, bold: true} }, colors: [ '604791', '1d6b99', '39a8a7', '0f8755', '76b349', 'f0af07', 'e37d05', 'cf513e', '96356f', '724173', '9c4f97', '696969' ] }); print(chart);
棒グラフ
特徴は y 軸に沿ってプロットされ、選択したプロパティの値でラベル付けされます。シリーズは、値が X 軸にプロットされるプロパティ名のリストで定義された隣接する棒で表されます。
コードエディタ(JavaScript)
// Import the example feature collection. var ecoregions = ee.FeatureCollection('projects/google/charts_feature_example'); // Define the chart and print it to the console. var chart = ui.Chart.feature .byFeature({ features: ecoregions.select('[0-9][0-9]_tmean|label'), xProperty: 'label', }) .setSeriesNames([ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]) .setChartType('BarChart') .setOptions({ title: 'Average Monthly Temperature by Ecoregion', hAxis: { title: 'Temperature (°C)', titleTextStyle: {italic: false, bold: true} }, vAxis: {title: 'Ecoregion', titleTextStyle: {italic: false, bold: true}}, colors: [ '604791', '1d6b99', '39a8a7', '0f8755', '76b349', 'f0af07', 'e37d05', 'cf513e', '96356f', '724173', '9c4f97', '696969' ] }); print(chart);
積み上げ棒グラフ
絶対
特徴は X 軸に沿ってプロットされ、選択したプロパティの値でラベル付けされます。シリーズは、プロパティ名のリストで定義された積み上げ列で表されます。値は、累積シリーズの合計として Y 軸にプロットされます。
コードエディタ(JavaScript)
// Import the example feature collection. var ecoregions = ee.FeatureCollection('projects/google/charts_feature_example'); // Define the chart and print it to the console. var chart = ui.Chart.feature .byFeature({ features: ecoregions.select('[0-9][0-9]_ppt|label'), xProperty: 'label' }) .setSeriesNames([ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]) .setChartType('ColumnChart') .setOptions({ title: 'Average Monthly Precipitation by Ecoregion', hAxis: {title: 'Ecoregion', titleTextStyle: {italic: false, bold: true}}, vAxis: { title: 'Precipitation (mm)', titleTextStyle: {italic: false, bold: true} }, colors: [ '604791', '1d6b99', '39a8a7', '0f8755', '76b349', 'f0af07', 'e37d05', 'cf513e', '96356f', '724173', '9c4f97', '696969' ], isStacked: 'absolute' }); print(chart);
相対
特徴は X 軸に沿ってプロットされ、選択したプロパティの値でラベル付けされます。シリーズは、プロパティ名のリストで定義された積み上げ棒グラフで表されます。値は、合計シリーズの割合として Y 軸にプロットされます。
コードエディタ(JavaScript)
// Import the example feature collection. var ecoregions = ee.FeatureCollection('projects/google/charts_feature_example'); // Define the chart and print it to the console. var chart = ui.Chart.feature .byFeature({ features: ecoregions.select('[0-9][0-9]_ppt|label'), xProperty: 'label' }) .setSeriesNames([ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]) .setChartType('ColumnChart') .setOptions({ title: 'Average Monthly Precipitation by Ecoregion', hAxis: {title: 'Ecoregion', titleTextStyle: {italic: false, bold: true}}, vAxis: { title: 'Precipitation (mm)', titleTextStyle: {italic: false, bold: true} }, colors: [ '604791', '1d6b99', '39a8a7', '0f8755', '76b349', 'f0af07', 'e37d05', 'cf513e', '96356f', '724173', '9c4f97', '696969' ], isStacked: 'percent' }); print(chart);
散布図
特徴は X 軸に沿ってプロットされ、選択したプロパティの値でラベル付けされます。シリーズは、値が Y 軸に沿ってプロットされるプロパティ名のリストで定義されたポイントで表されます。
コードエディタ(JavaScript)
// Import the example feature collection. var ecoregions = ee.FeatureCollection('projects/google/charts_feature_example'); // Define the chart and print it to the console. var chart = ui.Chart.feature .byFeature({ features: ecoregions, xProperty: 'label', yProperties: ['01_tmean', '07_tmean'] }) .setSeriesNames(['Jan', 'Jul']) .setChartType('ScatterChart') .setOptions({ title: 'Average Monthly Temperature by Ecoregion', hAxis: {title: 'Ecoregion', titleTextStyle: {italic: false, bold: true}}, vAxis: { title: 'Temperature (°C)', titleTextStyle: {italic: false, bold: true} }, pointSize: 10, colors: ['1d6b99', 'cf513e'], }); print(chart);
複合グラフ
特徴は X 軸に沿ってプロットされ、選択したプロパティの値でラベル付けされます。シリーズは、プロパティ名のリストで定義されたポイントと列で表され、値は Y 軸に沿ってプロットされます。このグラフは、2 つの軸とシリーズ固有のスタイル設定を使用して作成されています。
コードエディタ(JavaScript)
// Import the example feature collection. var ecoregions = ee.FeatureCollection('projects/google/charts_feature_example'); // Define the chart and print it to the console. var chart = ui.Chart.feature .byFeature({ features: ecoregions, xProperty: 'label', yProperties: ['06_ppt', '06_tmean'] }) .setSeriesNames(['Precipitation', 'Temperature']) .setChartType('ColumnChart') .setOptions({ title: 'Average June Temperature and Precipitation by Ecoregion', series: { 0: {targetAxisIndex: 1, type: 'bar', color: '1d6b99'}, 1: { targetAxisIndex: 0, type: 'line', lineWidth: 0, pointSize: 10, color: 'e37d05' } }, hAxis: {title: 'Ecoregion', titleTextStyle: {italic: false, bold: true}}, vAxes: { 0: { title: 'Temperature (°C)', baseline: 0, titleTextStyle: {italic: false, bold: true, color: 'e37d05'} }, 1: { title: 'Precipitation (mm)', titleTextStyle: {italic: false, bold: true, color: '1d6b99'} }, }, bar: {groupWidth: '40%'}, }); print(chart);
ui.Chart.feature.byProperty
設定例
ui.Chart.feature.byProperty
関数は辞書を受け取ります。この辞書に数値を割り当てることで、X 軸に沿ったプロパティ名のラベルと順序を制御できます。次の直交座標グラフでは、このオプションを使用して月のラベルを設定し、月の名前を月平均降水量の順序で並べ替えています。
縦棒グラフ
特徴プロパティは X 軸に沿ってプロットされ、辞書入力によってラベルが付けられ、並べ替えられます。指定されたプロパティの値は Y 軸に沿ってプロットされます。シリーズは、列で表される特徴で、選択したプロパティの値でラベル付けされます。棒グラフに変換するには、.setChartType('BarChart')
を使用します。
コードエディタ(JavaScript)
// Import the example feature collection. var ecoregions = ee.FeatureCollection('projects/google/charts_feature_example'); // Define a dictionary that associates property names with values and labels. var precipInfo = { '01_ppt': {v: 1, f: 'Jan'}, '02_ppt': {v: 2, f: 'Feb'}, '03_ppt': {v: 3, f: 'Mar'}, '04_ppt': {v: 4, f: 'Apr'}, '05_ppt': {v: 5, f: 'May'}, '06_ppt': {v: 6, f: 'Jun'}, '07_ppt': {v: 7, f: 'Jul'}, '08_ppt': {v: 8, f: 'Aug'}, '09_ppt': {v: 9, f: 'Sep'}, '10_ppt': {v: 10, f: 'Oct'}, '11_ppt': {v: 11, f: 'Nov'}, '12_ppt': {v: 12, f: 'Dec'} }; // Organize property information into objects for defining x properties and // their tick labels. var xPropValDict = {}; // Dictionary to codify x-axis property names as values. var xPropLabels = []; // Holds dictionaries that label codified x-axis values. for (var key in precipInfo) { xPropValDict[key] = precipInfo[key].v; xPropLabels.push(precipInfo[key]); } // Define the chart and print it to the console. var chart = ui.Chart.feature .byProperty({ features: ecoregions, xProperties: xPropValDict, seriesProperty: 'label' }) .setChartType('ColumnChart') .setOptions({ title: 'Average Ecoregion Precipitation by Month', hAxis: { title: 'Month', titleTextStyle: {italic: false, bold: true}, ticks: xPropLabels }, vAxis: { title: 'Precipitation (mm)', titleTextStyle: {italic: false, bold: true} }, colors: ['f0af07', '0f8755', '76b349'], }); print(chart);
折れ線グラフ
特徴プロパティは X 軸に沿ってプロットされ、辞書入力によってラベルが付けられ、並べ替えられます。指定されたプロパティの値は Y 軸に沿ってプロットされます。シリーズは、線で表され、選択したプロパティの値でラベル付けされた特徴です。
コードエディタ(JavaScript)
// Import the example feature collection. var ecoregions = ee.FeatureCollection('projects/google/charts_feature_example'); // Define a dictionary that associates property names with values and labels. var precipInfo = { '01_ppt': {v: 1, f: 'Jan'}, '02_ppt': {v: 2, f: 'Feb'}, '03_ppt': {v: 3, f: 'Mar'}, '04_ppt': {v: 4, f: 'Apr'}, '05_ppt': {v: 5, f: 'May'}, '06_ppt': {v: 6, f: 'Jun'}, '07_ppt': {v: 7, f: 'Jul'}, '08_ppt': {v: 8, f: 'Aug'}, '09_ppt': {v: 9, f: 'Sep'}, '10_ppt': {v: 10, f: 'Oct'}, '11_ppt': {v: 11, f: 'Nov'}, '12_ppt': {v: 12, f: 'Dec'} }; // Organize property information into objects for defining x properties and // their tick labels. var xPropValDict = {}; // Dictionary to codify x-axis property names as values. var xPropLabels = []; // Holds dictionaries that label codified x-axis values. for (var key in precipInfo) { xPropValDict[key] = precipInfo[key].v; xPropLabels.push(precipInfo[key]); } // Define the chart and print it to the console. var chart = ui.Chart.feature .byProperty({ features: ecoregions, xProperties: xPropValDict, seriesProperty: 'label' }) .setChartType('ScatterChart') .setOptions({ title: 'Average Ecoregion Precipitation by Month', hAxis: { title: 'Month', titleTextStyle: {italic: false, bold: true}, ticks: xPropLabels }, vAxis: { title: 'Precipitation (mm)', titleTextStyle: {italic: false, bold: true} }, colors: ['f0af07', '0f8755', '76b349'], lineSize: 5, pointSize: 0 }); print(chart);
面グラフ
特徴プロパティは X 軸に沿ってプロットされ、辞書入力によってラベルが付けられ、並べ替えられます。指定されたプロパティの値は Y 軸に沿ってプロットされます。シリーズは、線や陰影付き領域で表される特徴で、選択したプロパティの値でラベル付けされます。
コードエディタ(JavaScript)
// Import the example feature collection. var ecoregions = ee.FeatureCollection('projects/google/charts_feature_example'); // Define a dictionary that associates property names with values and labels. var precipInfo = { '01_ppt': {v: 1, f: 'Jan'}, '02_ppt': {v: 2, f: 'Feb'}, '03_ppt': {v: 3, f: 'Mar'}, '04_ppt': {v: 4, f: 'Apr'}, '05_ppt': {v: 5, f: 'May'}, '06_ppt': {v: 6, f: 'Jun'}, '07_ppt': {v: 7, f: 'Jul'}, '08_ppt': {v: 8, f: 'Aug'}, '09_ppt': {v: 9, f: 'Sep'}, '10_ppt': {v: 10, f: 'Oct'}, '11_ppt': {v: 11, f: 'Nov'}, '12_ppt': {v: 12, f: 'Dec'} }; // Organize property information into objects for defining x properties and // their tick labels. var xPropValDict = {}; // Dictionary to codify x-axis property names as values. var xPropLabels = []; // Holds dictionaries that label codified x-axis values. for (var key in precipInfo) { xPropValDict[key] = precipInfo[key].v; xPropLabels.push(precipInfo[key]); } // Define the chart and print it to the console. var chart = ui.Chart.feature .byProperty({ features: ecoregions, xProperties: xPropValDict, seriesProperty: 'label' }) .setChartType('AreaChart') .setOptions({ title: 'Average Ecoregion Precipitation by Month', hAxis: { title: 'Month', titleTextStyle: {italic: false, bold: true}, ticks: xPropLabels }, vAxis: { title: 'Precipitation (mm)', titleTextStyle: {italic: false, bold: true} }, colors: ['f0af07', '0f8755', '76b349'], lineSize: 5, pointSize: 0, curveType: 'function' }); print(chart);
円グラフ
円グラフは特徴であり、各スライスはプロパティラベルです。その値は、円グラフを構成するプロパティのすべての値の合計の割合としてキャストされます。
コードエディタ(JavaScript)
// Import the example feature collection. var ecoregions = ee.FeatureCollection('projects/google/charts_feature_example'); // Subset the forest ecoregion feature and select the monthly precipitation // properties, rename them as abbreviated months. var thisForest = ecoregions.filter(ee.Filter.eq('label', 'Forest')) .select(Object.keys(precipInfo), [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]); // Define the chart and print it to the console. var chart = ui.Chart.feature .byProperty({ features: thisForest, xProperties: [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ] }) .setChartType('PieChart') .setOptions({ title: 'Average Monthly Precipitation for Forest Ecoregion', colors: [ '604791', '1d6b99', '39a8a7', '0f8755', '76b349', 'f0af07', 'e37d05', 'cf513e', '96356f', '724173', '9c4f97', '696969' ] }); print(chart);
ドーナツグラフ
円グラフをドーナツグラフに変換するには、グラフ オプション pieHole
を設定します。ほとんどのグラフでは、0.4 ~ 0.6 の値が適しています。
コードエディタ(JavaScript)
// Import the example feature collection. var ecoregions = ee.FeatureCollection('projects/google/charts_feature_example'); // Subset the forest ecoregion feature and select the monthly precipitation // properties, rename them as abbreviated months. var thisForest = ecoregions.filter(ee.Filter.eq('label', 'Forest')) .select(Object.keys(precipInfo), [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]); // Define the chart and print it to the console. var chart = ui.Chart.feature .byProperty({ features: thisForest, xProperties: [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ] }) .setChartType('PieChart') .setOptions({ title: 'Average Monthly Precipitation for Forest Ecoregion', colors: [ '604791', '1d6b99', '39a8a7', '0f8755', '76b349', 'f0af07', 'e37d05', 'cf513e', '96356f', '724173', '9c4f97', '696969' ], pieHole: 0.4, }); print(chart);
ui.Chart.feature.groups
縦棒グラフ
特徴は X 軸に沿ってプロットされ、選択したプロパティの値でラベル付けされます。シリーズは、特定のプロパティの一意の値のセットによって定義される列で表されます。Y 軸の位置は、特定のプロパティの値によって定義されます。このプロットは、グラフの種類を 'ScatterChart'
(.setChartType('ScatterChart')
)に設定することで散布図に変更できます。時間の値が X 軸の変数である場合は、折れ線グラフ(.setChartType('LineChart')
)を使用することをおすすめします。
コードエディタ(JavaScript)
// Import the example feature collection. var ecoregions = ee.FeatureCollection('projects/google/charts_feature_example'); // Define the chart and print it to the console. var chart = ui.Chart.feature .groups({ features: ecoregions, xProperty: 'label', yProperty: '01_tmean', seriesProperty: 'warm' }) .setSeriesNames(['Warm', 'Cold']) .setChartType('ColumnChart') .setOptions({ title: 'Average January Temperature by Ecoregion', hAxis: {title: 'Ecoregion', titleTextStyle: {italic: false, bold: true}}, vAxis: { title: 'Jan temp (°C)', titleTextStyle: {italic: false, bold: true} }, bar: {groupWidth: '80%'}, colors: ['cf513e', '1d6b99'], isStacked: true }); print(chart);
ui.Chart.feature.histogram
x 軸は、選択したプロパティの値の範囲の値ビンによって定義されます。y 軸は、指定されたビン内の要素数です。
コードエディタ(JavaScript)
// Load PRISM climate normals image collection; convert images to bands. var normClim = ee.ImageCollection('OREGONSTATE/PRISM/Norm81m').toBands(); // Make a point sample of climate variables for a region in western USA. var region = ee.Geometry.Rectangle(-123.41, 40.43, -116.38, 45.14); var climSamp = normClim.sample(region, 5000); // Define the chart and print it to the console. var chart = ui.Chart.feature .histogram({features: climSamp, property: '07_ppt', maxBuckets: 30}) .setOptions({ title: 'July Precipitation Distribution for NW USA', hAxis: { title: 'Precipitation (mm)', titleTextStyle: {italic: false, bold: true} }, vAxis: { title: 'Pixel count', titleTextStyle: {italic: false, bold: true} }, colors: ['1d6b99'], legend: {position: 'none'} }); print(chart);