Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dgearthgrid merge with binned data gives holes etc. #39

Open
MartinBeal opened this issue Aug 29, 2019 · 0 comments
Open

dgearthgrid merge with binned data gives holes etc. #39

MartinBeal opened this issue Aug 29, 2019 · 0 comments

Comments

@MartinBeal
Copy link

Instead of selecting just grid cells with data using dgcellstogrid(), I would like to display the full grid, including cells with NA.

I tried doing this by replacing dgcellstogrid with dggearthgrid and then merging using merge(all=TRUE) but the result is a messed up grid.

Reproducible example using your vignette code:

library(dggridR)
library(dplyr)
dggs          <- dgconstruct(spacing=1000, metric=FALSE, resround='down')
data(dgquakes)
dgquakes$cell <- dgGEO_to_SEQNUM(dggs,dgquakes$lon,dgquakes$lat)$seqnum
cellcenters   <- dgSEQNUM_to_GEO(dggs,dgquakes$cell)
quakecounts   <- dgquakes %>% group_by(cell) %>% summarise(count=n())
#** HERE replace dgcellstogrid() with dgearthgrid()**
# grid          <- dgcellstogrid(dggs,quakecounts$cell,frame=TRUE,wrapcells=TRUE)
grid          <- dgearthgrid(dggs, frame=TRUE, wrapcells=TRUE)
# merge using all=T to include NAs
grid          <- merge(grid,quakecounts,by.x="cell",by.y="cell", all = TRUE)

#PLOT
countries <- map_data("world")
p <- ggplot() + 
    geom_polygon(data=countries, aes(x=long, y=lat, group=group), fill=NA, color="black")   +
    geom_polygon(data=grid,      aes(x=long, y=lat, group=group, fill=count), alpha=0.4)    +
    geom_path   (data=grid,      aes(x=long, y=lat, group=group), alpha=0.4, color="white") +
    geom_point  (aes(x=cellcenters$lon_deg, y=cellcenters$lat_deg)) +
    scale_fill_gradient(low="blue", high="red")
p

Rplot01

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant