I have a dictionary of % landcover from the 2016 NLCD. I am having trouble trying to make a bar chart to show the percentage of each land cover class in a given area (DEM vector). The dictionary is an object w/ 15 properties - I want the data in this object to be used for a bar chart.
///////////Load Landcover dataset////////////
var dataset = ee.Image('USGS/NLCD/NLCD2016')
.clip(aoi) ;
print(dataset);
var landcover = dataset.select('landcover');
var landcoverVis = {
min: 0.0,
max: 95.0,
palette: [
'000000',
'000000',
'000000',
'000000',
'000000',
'000000',
'000000',
'000000',
'000000',
'000000',
'000000',
'466b9f',
'd1def8',
'000000',
'000000',
'000000',
'000000',
'000000',
'000000',
'000000',
'000000',
'dec5c5',
'd99282',
'eb0000',
'ab0000',
'000000',
'000000',
'000000',
'000000',
'000000',
'000000',
'b3ac9f',
'000000',
'000000',
'000000',
'000000',
'000000',
'000000',
'000000',
'000000',
'000000',
'68ab5f',
'1c5f2c',
'b5c58f',
'000000',
'000000',
'000000',
'000000',
'000000',
'000000',
'000000',
'af963c',
'ccb879',
'000000',
'000000',
'000000',
'000000',
'000000',
'000000',
'000000',
'000000',
'000000',
'000000',
'000000',
'000000',
'000000',
'000000',
'000000',
'000000',
'000000',
'000000',
'dfdfc2',
'd1d182',
'a3cc51',
'82ba9e',
'000000',
'000000',
'000000',
'000000',
'000000',
'000000',
'dcd939',
'ab6c28',
'000000',
'000000',
'000000',
'000000',
'000000',
'000000',
'000000',
'b8d9eb',
'000000',
'000000',
'000000',
'000000',
'6c9fb8'
],
};
Map.addLayer(landcover, landcoverVis, 'Landcover');
//crop landcover by DEM_vector
var landcover_clip = landcover.clip(DEM_vector);
print(landcover_clip);
Map.addLayer(landcover_clip, {}, 'landcover_clip');
//Calculate percentage of landcover <5m
var frequency = landcover.reduceRegion({
reducer:ee.Reducer.frequencyHistogram(),
maxPixels:2e9,
geometry:DEM_vector
});
print('Pixel frequency', frequency);
//turn frequency into percentage
var dict = ee.Dictionary(frequency.get('landcover'));
var sum = ee.Array(dict.values()).reduce(ee.Reducer.sum(),[0]).get([0]);
var new_dict = dict.map(function(k,v) {
return ee.Number(v).divide(sum).multiply(100);
});
print('Land Cover (%)',new_dict);