Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(raster)
- library(ncdf4)
- library(reshape2)
- library(ggplot2)
- # Open file
- b = stack('Downloads/chirps-v2.0.2015.days_p25.nc')
- # Set coordinates
- lon = c(-47.5, -47.5, -44.5)
- lat = c(-18.5, -19.5, -20.5)
- xy = cbind(lon, lat)
- # Extract values from point
- e = extract(b, xy, df=TRUE)
- # Fix data frame
- df = data.frame(t(e)[-1,])
- df = cbind(as.Date(substr(rownames(df), 2, 14), "%Y.%m.%d"), df)
- row.names(df) = NULL; names(df) = c('date','location1', 'location2', 'location3')
- # Take a look
- head(df)
- # Melt
- df.m = melt(df, id.vars = 'date')
- # Plota como linhas
- ggplot(df.m) +
- geom_line(aes(x = date, y = value)) +
- facet_grid(.~variable)
- # Plota como barras
- ggplot(df.m, aes(x = date, y = value)) +
- geom_bar(stat = "identity") +
- facet_grid(.~variable)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement