\documentclass[a4paper, oneside, 10pt]{article}
\usepackage[unicode]{hyperref}
\usepackage[utf8x]{inputenc}
\usepackage[english]{babel}
\usepackage{listings}
\date{\today}
\title{}
\author{}
\begin{document}



\section{\texorpdfstring{Trablaho Final}{Trablaho Final}}
\label{sec:trablaho_final}


\subsubsection{\texorpdfstring{Código da função}{Codigo da funao}}
\label{sec:codigo_da_funao}
\lstset{frame=single}
\begin{lstlisting}


ClustDistSpat <-function(pts, X, Y, lon, lat)
  
{

    require("maptools")
    require("ggmap")
    require("ggplot2")
    require("plyr")
    require("fossil")
  
  pts1_a<-readShapePoints("pts")
  
  pts1<-as.data.frame(pts1_a)
  
  #Obtain the layers from Google Maps
  
  map <- get_map(location = c(lon=lon, lat=lat),zoom = "auto")
  # map zoom, an integer from 3 (continent) to 21 (building)
  
  ggmap(map)
  
  mapPoints <- ggmap(map) + geom_point(aes(X =X, Y =Y), data=pts1, alpha = .5) 
  
  ##Cluster analysis
  
  dist.g <- earth.dist(pts1)  
  
  kmean <- kmeans(dist.g,centers=5)
  #centers is the number of clusters k
  
  hcluster <- hclust(dist.g,method="complete")    
  
  clust <- cutree(hcluster, k=5 )
  
  set.seed(123)
  
  pts1a$clust <- cutree(hcluster,k=5)
  
  results<- ggmap(map)+geom_point(data=pts1, aes(x=X, y=Y, color=factor(clust)), size=4)+
    scale_color_discrete("Cluster") + coord_fixed()
  
  return (results)
}

\end{lstlisting}



\href{media/bie5782/01_curso_atual/alunos/trabalho_final/miroslav/funcaoclustdistspatfinal.r}{funcaoclustdistspatfinal.r}

\href{media/bie5782/01_curso_atual/alunos/trabalho_final/miroslav/scripthelpclustdistspat.r}{scripthelpclustdistspat.r}

\end{document}
