Q:

How can I plot values over a raster map?

I have a US raster map with certain range of values that I imported

I want to overlay points on it that come from a CSV file in this format: dput(droplevels(head(points,10))) : 
    points <- structure(list(lat = c(37.423333, 37.423333, 35.896667, 32.834722, 
32.834722, 32.834722, 32.834722, 32.834722, 32.834722, 32.834722
), lon = c(-122.188333, -122.188333, -121.087222, -116.622222, 
-116.622222, -116.622222, -116.622222, -116.622222, -116.622222, 
-116.622222)), .Names = c("lat", "lon"), row.names = c(NA, 10L
), class = "data.frame")

etc.
I tried fortify(prcp) but that led to this error:
Error: ggplot2 doesn't know how to deal with data of class RasterLayer
How can I do it? 
TRY:
library(raster)
library(sp)

coordinates(points) = ~lon+lat
proj4string(points) <- CRS("+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0")

r <- getData("worldclim",var="bio",res=10)
r<-r[[12]] #Annual Precipitation
names(r) <- c("Prec")
r <- crop(r, extent(-130, -60, 20, 60))
spplot(r) + layer(panel.points(x, y, col="green", cex=0.1, pch=1), data=points)

But the output is all green somehow even though points should have only 9000 points.

A:

Try this solution:
library(raster)
library(sp)
library(latticeExtra)

points <- structure(list(lat = c(37.423333, 37.423333, 35.896667, 32.834722, 
32.834722, 32.834722, 32.834722, 32.834722, 32.834722, 32.834722
), lon = c(-122.188333, -122.188333, -121.087222, -116.622222, 
-116.622222, -116.622222, -116.622222, -116.622222, -116.622222, 
-116.622222)), .Names = c("lat", "lon"), row.names = c(NA, 10L
), class = "data.frame")

coordinates(points) = ~lon+lat
proj4string(points) <- CRS("+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0")

r <- getData("worldclim",var="bio",res=10)
r<-r[[12]] #Annual Precipitation
names(r) <- c("Prec")
r <- crop(r, extent(-130, -60, 20, 60))

spplot(r)+spplot(points, col.regions="green")

