When using plot_geo on data which crosses the 180th meridian the add_lines function attempts to tie together the first and last data points, causing a weird behavior where the trace basically fabricates data and ruins the plot. Has anyone seen this behavior before or know a fix for it? I’ve provided an example below that can be copy / pasted.
# Generate data which crosses the 180 meridian
lon <- c(seq(1:179), -179, -178, -177)
lat <- rep(25, length(lon))
geo <- list(
showland = TRUE,
showlakes = TRUE,
showcountries = TRUE,
showocean = TRUE,
countrywidth = 0.5,
landcolor = toRGB("#90EE90"),
lakecolor = toRGB("white"),
oceancolor = toRGB("#F0F8FF"),
projection = list(
type = 'orthographic',
rotation = list(
lon = -60,
lat = 20,
roll = 0
)
),
lonaxis = list(
showgrid = TRUE,
gridcolor = toRGB("gray40"),
gridwidth = 0.5
),
lataxis = list(
showgrid = TRUE,
gridcolor = toRGB("gray40"),
gridwidth = 0.5
)
)
p <- plot_geo() %>%
add_lines(x = lon, y = lat) %>%
layout(
showlegend = FALSE, geo = geo,
title = 'Contour lines over globe<br>(Click and drag to rotate)'
)
p