```r
hh_habitat<-sprintf("select main_habit mhabitat, 
s1habtype,s2habtype,s3habtype habitat,
st_intersection(h.geom,s.geom) geom from 
(%s) s,
ph_v2_1 h 
where st_intersects(h.geom,s.geom)",query)

habitats<-st_read(conn, query=hh_habitat)

habitats$area <- st_area(habitats)

habitats%>% st_buffer(0.001)%>% group_by(mhabitat) %>% summarise(area=sum(area))-> habitats



qtm(habitats, "mhabitat") +tm_style("classic")
```

<img src="Quantitative_and_Spatial_files/figure-html/unnamed-chunk-212-1.png" width="672" />