I'm looking to plot data from a netCDF from the following source:
Just some simple, but large, files with PM 2.5 concentrations, latitudes, and longitudes.
I'm looking to plot this data on a map of Massachusetts.
Currently, I'm getting the following error:
Error: Aesthetics must be either length 1 or the same as the data (286): x
And the following is my code:
library(chron) library(RColorBrewer) library(lattice) library(ncdf4) library(raster) library(ggplot2) library(ggmap) library(maps) library(mapdata) memory.limit(size=56000) getwd() wd <- "C:/Users/tadams15/Desktop/Practicum/vd" setwd(wd) file <- "1adjust.nc" ncin <- nc_open(file) print(ncin) # Displays plenty of information about netCDF lat <-ncvar_get(ncin,"LAT") lon <-ncvar_get(ncin,"LON") pm <- ncvar_get(ncin,"PM25") states <- map_data("state") Mass <- subset(states,region == 'massachusetts') ggplot(data = Mass) image(pm) lat.df <- data.frame(lat) lon.df <- data.frame(lon) pm.df<- data.frame(pm) m <- map_data('state',region='Massachusetts') graph <-ggplot() + geom_polygon( data=m, aes(x=lon, y=lat,group=group),colour="black", fill="white" )+ geom_point(data=pm,aes(x=lon,y=lat),,colour="red",)+ ggtitle("Distribution of Flash Flood Events in CONUS")+ xlab('Longitude')+ ylab('Latitude')+ coord_fixed() print(graph)
I was wondering if anyone was comfortable with the ggplot function and whether or not any help could be offered. I'm very new to R and even newer to managing netCDF file types. Any help would be greatly appreciated!