# unsupervised classification of a raster in R: the layer-stack or part one.

[This article was first published on

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

**geo-affine » R**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

In my last post I was explaining the usage of QGis to do a layerstack of a Landsat-scene. Due to the fact that further research and trying out resulted in frustration I decided to stick with a software I know well: R.

So download the needed layers here and open up your flavoured version of R (in my case RStudio).

What do we need is a package called raster

install.packages("raster") library("raster")

Now define the working directory where your ETM-bands are stored which is “ETM” in my case:

setwd("~/wd_r/ETM")

Let’s do the last step and create the stack using one line and store this raster object using a second line:

A=stack(c("p134r027_7dt20020722.SR.b01.tif","p134r027_7dt20020722.SR.b02.tif","p134r027_7dt20020722.SR.b03.tif","p134r027_7dt20020722.SR.b04.tif","p134r027_7dt20020722.SR.b05.tif", "p134r027_7dt20020722.SR.b07.tif")) writeRaster(A, filename="merge.tif") plotRGB(A, 3, 2, 1, stretch="hist")

That’s it. Easy, wasn’t it?

To

**leave a comment**for the author, please follow the link and comment on their blog:**geo-affine » R**.R-bloggers.com offers

**daily e-mail updates**about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.