ui.Chart.image
모듈에는 지역별로 Image
객체를 줄이고 결과에서 차트를 렌더링하는 함수 집합이 포함되어 있습니다. 함수를 선택하면 차트의 데이터 배열이 결정됩니다. 즉, x축 및 y축 값을 정의하는 항목과 계열을 정의하는 항목이 결정됩니다. 다음 함수 설명과 예를 사용하여 목적에 가장 적합한 함수와 차트 유형을 결정하세요.
차트 함수
다음 플롯 다이어그램을 시각적 가이드로 사용하여 각 함수가 차트에서 이미지 영역 축소 결과를 정렬하는 방식(즉, x 값, y 값, 계열을 정의하는 요소)을 이해하세요.
감소 영역은 선택한 지형지물 속성의 값으로 라벨이 지정되어 x축을 따라 표시됩니다. 계열은 지역 축소 결과가 y축을 따라 표시되는 대역 이름으로 정의됩니다.
밴드는 x축을 따라 표시됩니다. 계열은 지형지물 속성 값으로 라벨이 지정됩니다. 각 계열 지형지물의 도형으로 정의된 영역의 감소가 y축을 따라 표시됩니다.
데이터 범위는 X축을 따라 표시됩니다. 계열은 클래스 범위 내 고유한 값으로 표시됩니다. Y축 위치는 각 계열을 구성하는 픽셀의 영역 축소 결과에 따라 정의됩니다.
선택한 밴드 값의 빈도 히스토그램
- X축: 선택한 밴드 값의 히스토그램 버킷
- Y축: 각 히스토그램 버킷에 적합한 픽셀의 빈도
예시 데이터
다음 예에서는 이미지 데이터를 줄일 지역을 정의하는 세 가지 생태 지역 지형지물로 구성된 FeatureCollection
를 사용합니다. Image
데이터는 PRISM 기후 평균으로, 밴드는 월별 기후 변수를 나타냅니다. 예를 들면 7월 강수량 또는 1월 평균 기온
이 확장 소재가 어떻게 만들어졌는지 알아보기
ui.Chart.image.byRegion
열 차트
이 예에서는 월별 평균 기온을 나타내는 이미지 밴드가 세 개의 생태 지역 중 각각을 교차하는 픽셀 간의 평균으로 줄어듭니다. 결과는 생태 지역별로 월별 열로 표시되며 열 높이는 각 월별 평균 온도를 나타냅니다.
코드 편집기 (JavaScript)
// Import the example feature collection. var ecoregions = ee.FeatureCollection('projects/google/charts_feature_example'); // Load PRISM climate normals image collection; convert images to bands. var normClim = ee.ImageCollection('OREGONSTATE/PRISM/Norm81m').toBands(); // Define the chart and print it to the console. var chart = ui.Chart.image .byRegion({ image: normClim.select('[0-9][0-9]_tmean'), regions: ecoregions, reducer: ee.Reducer.mean(), scale: 500, 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);
막대 그래프
이전 열 차트는 .setChartType()
입력을 'ColumnChart'
에서 'BarChart'
로 변경하여 막대 그래프로 렌더링할 수 있습니다.
var chart = ui.Chart.image .byRegion({ image: normClim.select('[0-9][0-9]_tmean'), regions: ecoregions, reducer: ee.Reducer.mean(), scale: 500, 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' ] });
누적 열 차트
isStacked
차트 옵션은 차트 열을 누적할지 여부를 지정합니다.
비슷한 사진을 겹쳐서 표시하는 방법에는 여러 가지 옵션이 있습니다. 다음 예는 'absolute'
및 'relative'
옵션을 사용하는 방법을 보여줍니다.
절대
절대 누적 막대 그래프는 기여하는 범주형 변수 계열의 증분으로 숫자 변수의 합계를 나타냅니다. 예를 들어 이 예에서는 총 강수량이 생태 지역별로 1년 동안의 월별 강수량 누적 값으로 표시됩니다. 월별 총 강수량은 이미지 밴드에서 파생됩니다. 각 밴드는 특정 월의 평균 총 강수량 그리드를 나타내며, 세 개의 생태 지역 중 하나와 교차하는 픽셀의 평균으로 줄입니다. 결과를 절댓값으로 형식 지정하기 위해 isStacked
차트 옵션이 'absolute'
로 설정됩니다.
코드 편집기 (JavaScript)
// Import the example feature collection. var ecoregions = ee.FeatureCollection('projects/google/charts_feature_example'); // Load PRISM climate normals image collection; convert images to bands. var normClim = ee.ImageCollection('OREGONSTATE/PRISM/Norm81m').toBands(); // Define the chart and print it to the console. var chart = ui.Chart.image .byRegion({ image: normClim.select('[0-9][0-9]_ppt'), regions: ecoregions, reducer: ee.Reducer.mean(), scale: 500, 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);
상대적
isStacked
차트 옵션을 'absolute'
에서 'relative'
로 변경하여 이전 절대 누적 막대 차트를 상대 누적 막대 차트로 변환합니다. 상대적 누적 막대 그래프는 기여하는 범주형 변수 계열의 비율을 숫자 변수의 합계에 관련시킵니다.
예를 들어 이 예시에서는 월별 강수량을 생태 지역별 연간 총 강수량의 비율로 표시합니다.
var chart = ui.Chart.image .byRegion({ image: normClim.select('[0-9][0-9]_ppt'), regions: ecoregions, reducer: ee.Reducer.mean(), scale: 500, 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: 'relative' });
분산형 차트
콜로라도주에 있는 무작위 위치 샘플의 1월과 7월 평균 기온을 고도 함수로 표시합니다. DEM은 도형 및 고도 속성이 있는 FeatureCollection
를 반환하는 sample
함수를 사용하여 샘플링됩니다. 그러면 결과 FeatureCollection
가 ui.Chart.image.byRegion
함수의 regions
매개변수에 대한 인수로 사용됩니다.
계열은 입력 기후 평균 이미지의 선택된 밴드에 의해 정의됩니다.
코드 편집기 (JavaScript)
// Load SRTM elevation data. var elev = ee.Image('CGIAR/SRTM90_V4').select('elevation'); // Subset Colorado from the TIGER States feature collection. var colorado = ee.FeatureCollection('TIGER/2018/States') .filter(ee.Filter.eq('NAME', 'Colorado')); // Draw a random sample of elevation points from within Colorado. var samp = elev.sample( {region: colorado, scale: 30, numPixels: 500, geometries: true}); // Load PRISM climate normals image collection; convert images to bands. var normClim = ee.ImageCollection('OREGONSTATE/PRISM/Norm81m').toBands(); // Define the chart and print it to the console. var chart = ui.Chart.image .byRegion({ image: normClim.select(['01_tmean', '07_tmean']), regions: samp, reducer: ee.Reducer.mean(), scale: 500, xProperty: 'elevation' }) .setSeriesNames(['Jan', 'Jul']) .setChartType('ScatterChart') .setOptions({ title: 'Average Monthly Colorado Temperature by Elevation', hAxis: { title: 'Elevation (m)', titleTextStyle: {italic: false, bold: true} }, vAxis: { title: 'Temperature (°C)', titleTextStyle: {italic: false, bold: true} }, pointSize: 4, dataOpacity: 0.6, colors: ['1d6b99', 'cf513e'], }); print(chart);
콤보 차트
ee.FeatureCollection
의 세 생태 지역의 경우 6월의 평균 기온과 강수량이 각각 표시됩니다. 결과는 이미지의 지역 감소에서 파생되며 각 밴드는 월별 강수량과 온도를 나타내는 기후 평균 그리드입니다. 6월 온도와 강수량을 나타내는 밴드는 하위 집합입니다. 강수량과 온도는 서로 다른 단위이므로 series
및 vAxes
옵션을 설정하여 두 개의 Y축을 사용합니다. series.targetAxisIndex
옵션을 사용하여 오른쪽 및 왼쪽 y축에 표시할 변수를 정의합니다. 계열별 기호 (점 및 열)는 두 변수가 서로 다른 단위를 갖는 것으로 더 쉽게 구분하는 데 사용됩니다.
코드 편집기 (JavaScript)
// Import the example feature collection. var ecoregions = ee.FeatureCollection('projects/google/charts_feature_example'); // Load PRISM climate normals image collection; convert images to bands. var normClim = ee.ImageCollection('OREGONSTATE/PRISM/Norm81m').toBands(); // Define the chart and print it to the console. var chart = ui.Chart.image .byRegion({ image: normClim.select(['06_tmean', '06_ppt']), regions: ecoregions, reducer: ee.Reducer.mean(), scale: 500, xProperty: 'label' }) .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.image.regions
설정 예시
ui.Chart.image.regions
함수는 숫자 값을 할당하여 x축의 밴드 이름 라벨과 순서를 제어할 수 있는 목록을 허용합니다. 다음 차트에서는 이 옵션을 사용하여 밴드 이름을 월 라벨로 설정하고 월별 평균 강수량을 기준으로 시간순으로 정렬합니다.
열 차트
이 차트는 3개 생태 지역의 월별 총 평균 강수량을 보여줍니다.
결과는 각 밴드가 특정 월의 평균 총 강수량 그리드인 이미지의 지역 감소에서 파생됩니다. 밴드는 x축을 따라 표시되고 지역은 계열을 정의합니다. x축의 맞춤 배열을 위한 xLabels
및 ticks
차트 옵션의 입력을 정의하는 데 사용되는 클라이언트 측 작업에 유의하세요. setOptions
함수에 제공된 옵션이 클라이언트 측 객체여야 하므로 클라이언트 작업이 필요합니다(구분을 이해하려면 클라이언트와 서버 비교를 참고하세요). 막대 그래프로 변환하려면 'BarChart'
를 .setChartType()
입력으로 사용합니다.
코드 편집기 (JavaScript)
// Import the example feature collection. var ecoregions = ee.FeatureCollection('projects/google/charts_feature_example'); // Load PRISM climate normals image collection, convert images to bands, and // subset precipitation bands. var precip = ee.ImageCollection('OREGONSTATE/PRISM/Norm81m') .toBands() .select('[0-9][0-9]_ppt'); // Define a dictionary that associates band 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 precipitation information into objects for defining x values and // their tick labels. Note that chart options provided to the .setOptions() // function must be client-side objects, which is why a client-side for // loop is used to iteratively populate lists from the above dictionary. var xPropVals = []; // List to codify x-axis band names as values. var xPropLabels = []; // Holds dictionaries that label codified x-axis values. for (var key in precipInfo) { xPropVals.push(precipInfo[key].v); xPropLabels.push(precipInfo[key]); } // Define the chart and print it to the console. var chart = ui.Chart.image .regions({ image: precip, regions: ecoregions, reducer: ee.Reducer.mean(), scale: 5e3, seriesProperty: 'label', xLabels: xPropVals }) .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);
선 차트
이전 열 차트는 .setChartType()
입력을 'ColumnChart'
에서 'LineChart'
로 변경하여 선 차트로 렌더링할 수 있습니다.
var chart = ui.Chart.image .regions({ image: precip, regions: ecoregions, reducer: ee.Reducer.mean(), scale: 500, seriesProperty: 'label', xLabels: xPropVals }) .setChartType('LineChart') .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 });
영역 차트
이전 열 차트는 .setChartType()
입력을 'ColumnChart'
에서 'AreaChart'
로 변경하여 영역 차트로 렌더링할 수 있습니다.
var chart = ui.Chart.image .regions({ image: precip, regions: ecoregions, reducer: ee.Reducer.mean(), scale: 500, seriesProperty: 'label', xLabels: xPropVals }) .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 });
원형 차트
월별 평균 강수량은 숲 생태 지역의 연간 평균 총 강수량에 대한 비율로 표시됩니다. 월별 강수를 나타내는 이미지 밴드는 기후 평균 데이터 세트에서 하위 집합으로 추출되고 생태 지역을 교차하는 픽셀의 평균으로 줄입니다.
코드 편집기 (JavaScript)
// Import the example feature collection, subset the forest ecoregion. var forest = ee.FeatureCollection('projects/google/charts_feature_example') .filter(ee.Filter.eq('label', 'Forest')); // Load PRISM climate normals image collection, convert images to bands. var normClim = ee.ImageCollection('OREGONSTATE/PRISM/Norm81m').toBands(); // Define x-axis labels to replace default band names. var monthNames = [ '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.image .regions({ image: normClim.select('[0-9][0-9]_ppt'), regions: forest, reducer: ee.Reducer.mean(), scale: 5e3, seriesProperty: 'label', xLabels: monthNames }) .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을 사용해 보세요.
var chart = ui.Chart.image .regions({ image: normClim.select('[0-9][0-9]_ppt'), regions: forest, reducer: ee.Reducer.mean(), scale: 5e3, seriesProperty: 'label', xLabels: monthNames }) .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 });
ui.Chart.image.byClass
선 차트
ui.Chart.image.byClass
함수는 '클래스 밴드'의 분류된 영역 내 픽셀의 밴드 값 통계를 표시합니다. 이 예에서는 세 개의 생태 지역의 스펙트럼 프로필을 표시하는 데 사용됩니다. 생태지역 지형지물은 래스터화되어 MODIS 표면 반사율 (SR) 이미지에 밴드로 추가됩니다. 각 생태 지역 클래스 및 반사율 밴드의 경우 각 픽셀 평균이 계산되어 Y축에 표시됩니다. MODIS SR 밴드의 중심 파장은 x축 눈금과 라벨을 정의합니다. 선을 부드럽게 하기 위해 curveType
선 차트 옵션이 'function'
로 설정됩니다.
코드 편집기 (JavaScript)
// Import the example feature collection. var ecoregions = ee.FeatureCollection('projects/google/charts_feature_example'); // Convert ecoregion feature collection to a classified image. var regionsBand = ecoregions .reduceToImage({properties: ['value'], reducer: ee.Reducer.first()}) .rename('class'); // Define a MODIS surface reflectance composite. var modisSr = ee.ImageCollection('MODIS/006/MOD09A1') .filter(ee.Filter.date('2018-06-01', '2018-09-01')) .select('sur_refl_b0[0-7]') .mean(); // Reorder reflectance bands by ascending wavelength and // add the classified ecoregions image as a band to the SR collection and var modisSrClass = modisSr.select([2, 3, 0, 1, 4, 5, 6]).addBands(regionsBand); // Define a list of MODIS SR wavelengths for x-axis labels. var wavelengths = [469, 555, 655, 858, 1240, 1640, 2130]; // Define the chart and print it to the console. var chart = ui.Chart.image .byClass({ image: modisSrClass, classBand: 'class', region: ecoregions, reducer: ee.Reducer.mean(), scale: 500, classLabels: ['Desert', 'Forest', 'Grassland'], xLabels: wavelengths }) .setChartType('ScatterChart') .setOptions({ title: 'Ecoregion Spectral Signatures', hAxis: { title: 'Wavelength (nm)', titleTextStyle: {italic: false, bold: true}, viewWindow: {min: wavelengths[0], max: wavelengths[6]} }, vAxis: { title: 'Reflectance (x1e4)', titleTextStyle: {italic: false, bold: true} }, colors: ['f0af07', '0f8755', '76b349'], pointSize: 0, lineSize: 5, curveType: 'function' }); print(chart);
ui.Chart.image.histogram
미국 유타주 솔트레이크시티 주변 지역 내 픽셀 값의 히스토그램이 세 가지 MODIS 표면 반사율 밴드에 대해 표시됩니다.
코드 편집기 (JavaScript)
// Define a MODIS surface reflectance composite. var modisSr = ee.ImageCollection('MODIS/006/MOD09A1') .filter(ee.Filter.date('2018-06-01', '2018-09-01')) .select(['sur_refl_b01', 'sur_refl_b02', 'sur_refl_b06']) .mean(); // Define a region to calculate histogram for. var histRegion = ee.Geometry.Rectangle([-112.60, 40.60, -111.18, 41.22]); // Define the chart and print it to the console. var chart = ui.Chart.image.histogram({image: modisSr, region: histRegion, scale: 500}) .setSeriesNames(['Red', 'NIR', 'SWIR']) .setOptions({ title: 'MODIS SR Reflectance Histogram', hAxis: { title: 'Reflectance (x1e4)', titleTextStyle: {italic: false, bold: true}, }, vAxis: {title: 'Count', titleTextStyle: {italic: false, bold: true}}, colors: ['cf513e', '1d6b99', 'f0af07'] }); print(chart);