title: Extract Raster Pixels Values Using Vector Polygons in R
body: <p>I have been struggling with this for hours.
  I have a shapefile (called "shp") containing 177 polygons i.e. 177 counties. This shapefile is overlaid on a raster. My raster (called "ras")  is made of pixels having different pollution values. </p>
  
  <p>Now I would like to extract all pixel values and their number of occurrences for each polygon. </p>
  
  <p>This is exactly what the QGIS function "zonal histogram" is doing. But I would like to do the exact same thing in R. </p>
  
  <p>I tried the extract() function and I managed to get a mean value per county, which is already a first step, but I would like to make a pixels distribution (histogram).</p>
  
  <p>Could someone give me a hand ?</p>
  
  <p>Many thanks,</p>
  
  <p>Marie-Laure</p>