Skip to content

Commit

Permalink
fix ice in gg
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondben committed Jun 4, 2019
1 parent 96f9c8b commit 83df0f4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 31 deletions.
11 changes: 11 additions & 0 deletions R/gg.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ SOgg_notauto <- function(x) {
this <- suppressWarnings(sf::st_intersection(buf, x$coastline$plotargs$x))
p <- p + geom_sf(data = this, fill = x$coastline$plotargs$col, col = x$coastline$plotargs$border, inherit.aes = FALSE)
}
if (!is.null(x$ice)) {
## TODO check that this trimming is robust
this <- suppressWarnings(sf::st_intersection(buf, x$ice$plotargs$x))
p <- p + geom_sf(data = this, fill = x$ice$plotargs$col, col = x$ice$plotargs$border, inherit.aes = FALSE)
}


## fronts
Expand Down Expand Up @@ -349,6 +354,12 @@ SOgg2_notauto <- function(x) {
out$coastline <- as_plotter(plotfun = "ggplot2::geom_sf", plotargs = list(data = this, fill = x$coastline$plotargs$col, col = x$coastline$plotargs$border, inherit.aes = FALSE))
out$plot_sequence <- c(out$plot_sequence, "coastline")
}
if (!is.null(x$ice)) {
## TODO check that this trimming is robust
this <- suppressWarnings(sf::st_intersection(buf, x$ice$plotargs$x))
out$ice <- as_plotter(plotfun = "ggplot2::geom_sf", plotargs = list(data = this, fill = x$ice$plotargs$col, col = x$ice$plotargs$border, inherit.aes = FALSE))
out$plot_sequence <- c(out$plot_sequence, "ice")
}

## fronts
if (!is.null(x$fronts)) {
Expand Down
63 changes: 32 additions & 31 deletions R/ggauto_map.R
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
SOgg_auto <- function(x) {
if (!inherits(x, "SOmap_auto")) stop("x must be an SOmap_auto object as generated by SOmap_auto")
myext <- extent(x$target)
## plot bathymetry
bdf <- raster::as.data.frame(x$bathy, xy = TRUE)
names(bdf) <- c("Longitude","Latitude","Depth")
p <- ggplot(data = bdf, aes_string(x = "Longitude", y = "Latitude")) + geom_raster(aes_string(fill = "Depth"))
p <- p + coord_sf(default = TRUE) ## default = TRUE makes this the default coordinate system for geom_sf objects
p <- p + scale_fill_gradientn(colours = x$bathy_palette, na.value = "#FFFFFF00") #need to duplicate for guide=FALSE
if (!inherits(x, "SOmap_auto")) stop("x must be an SOmap_auto object as generated by SOmap_auto")
myext <- extent(x$target)
## plot bathymetry
bdf <- raster::as.data.frame(x$bathy, xy = TRUE)
names(bdf) <- c("Longitude","Latitude","Depth")
p <- ggplot(data = bdf, aes_string(x = "Longitude", y = "Latitude")) + geom_raster(aes_string(fill = "Depth"))
p <- p + coord_sf(default = TRUE) ## default = TRUE makes this the default coordinate system for geom_sf objects
p <- p + scale_fill_gradientn(colours = x$bathy_palette, na.value = "#FFFFFF00") #need to duplicate for guide=FALSE

if (!is.null(x$coastline)) {
this <- suppressWarnings(sf::st_as_sf(x$coastline$data))
p <- p + geom_sf(data = this, fill = x$coastline$fillcol, col = x$coastline$linecol, inherit.aes = FALSE)
}
if (!is.null(x$coastline)) {
this <- suppressWarnings(sf::st_as_sf(x$coastline$data))
p <- p + geom_sf(data = this, fill = x$coastline$fillcol, col = x$coastline$linecol, inherit.aes = FALSE)
}
if (!is.null(x$ice)) {
this <- suppressWarnings(sf::st_as_sf(x$ice$data))
p <- p + geom_sf(data = this, fill = x$ice$fillcol, col = x$ice$linecol, inherit.aes = FALSE)
}

if (x$contours) {
this <- suppressWarnings(sf::st_as_sf(x$coastline$data))
p <- p + geom_sf(data = this, fill = x$coastline$fillcol, col = x$coastline$linecol, inherit.aes = FALSE)
}
if (x$contours) {
this <- suppressWarnings(sf::st_as_sf(x$coastline$data))
p <- p + geom_sf(data = this, fill = x$coastline$fillcol, col = x$coastline$linecol, inherit.aes = FALSE)
}

if (!is.null(x$graticule)) {
p <- p + geom_sf(data = x$graticule, col = "grey", inherit.aes = FALSE)}
if (!is.null(x$graticule)) {
p <- p + geom_sf(data = x$graticule, col = "grey", inherit.aes = FALSE)}

if(!is.null(x$lines_data)){
p <- p + geom_line(data= as.data.frame(x$lines_data), aes_string(x="x", y="y"), col=x$lcol, linetype=x$llty, size=x$llwd )
}
if(!is.null(x$lines_data)){
p <- p + geom_line(data = setNames(as.data.frame(x$lines_data), c("x", "y")), aes_string(x = "x", y = "y"), col = x$lcol, linetype = x$llty, size = x$llwd)
}

if(!is.null(x$points_data)){
p <- p + geom_point(data= as.data.frame(x$points_data), aes_string(x="x", y="y"), col=x$pcol, shape=x$ppch, size=x$pcex )
}
if(!is.null(x$points_data)){
p <- p + geom_point(data = setNames(as.data.frame(x$points_data), c("x", "y")), aes_string(x = "x", y = "y"), col = x$pcol, shape = x$ppch, size = x$pcex)
}

p <- p + theme(axis.title = element_blank(),
panel.border = element_rect(color = "black", fill=NA),
panel.background = element_blank(),
axis.text.x = element_text(angle = 90, vjust=0.5))+
scale_x_continuous(expand = c(0,0))+
scale_y_continuous(expand = c(0,0))
}
p <- p + theme(axis.title = element_blank(), panel.border = element_rect(color = "black", fill = NA),
panel.background = element_blank(), axis.text.x = element_text(angle = 90, vjust = 0.5)) +
scale_x_continuous(expand = c(0, 0)) + scale_y_continuous(expand = c(0, 0))
}

0 comments on commit 83df0f4

Please sign in to comment.