hermesh2
11/22/2015 - 2:19 AM

## 07 Solucion6.R

``````# Solution 7
# S plot heatmap ----------------------------------------------------------
x <- interaction(x.bin, y.bin, sep = "_") %>% levels %>% strsplit(split = "_") %>%
unlist %>% as.numeric() %>% matrix(ncol= 2, byrow = T) %>% data.frame
names( x) <- c("x.bin" , "y.bin" )
elevation.df <- data.frame(freq2D = as.vector(freq2D), x.bin = x\$x.bin, y.bin = x\$y.bin )

elevation.loess <- loess(freq2D ~ x.bin*y.bin, data = elevation.df, degree = 2, span = 0.25) # Predict the gradients
elevation.fit <- expand.grid(list(x.bin = seq(0, 1000, 10), y.bin = seq(0, 700, 10))) # Fit the values in the curve
z <- predict(elevation.loess, newdata = elevation.fit)
elevation.fit\$Height <- as.numeric(z)
elevation.fit\$Height[ is.na( elevation.fit\$Height )] <- 0

colfunc <- colorRampPalette(c("darkblue", "lightblue", "green", "yellow", "red"))
p <- ggplot(elevation.fit, aes(x.bin, y.bin, fill = Height)) + geom_tile() +
geom_point(data= elevation.fit, aes(x = x.bin, y =y.bin),  # coordinates
color="black", # Color point
# position=position_jitter(w=0.01,h=0.01), # Point plot desviation
alpha=0.05) +
xlab("X Coordinate") + ylab("Y Coordinate") +