I am having a strange issue in ggplot with strange lines appearing on the initial play of my animation (in viewer and saved to HTML page through Rstudio). I do not know what could be causing this, and have been stuck on this for multiple days. After the initial start of my program (initial press of play) everything looks correct and as it should. But if its the first press, or the first open of the saved html page, then I see these strange lines. Below is the code I have used to create this map, and also a link to a video of the issue, as it is reproducible. Simply run this code in r and press the play button. I am using simple lat lon points in their respective columns, and an optional radius. The column formatting is "Date,Name,lat,lon,optrad". Any help on this is appreciated!
link to example video: https://i.stack.imgur.com/rYtoW.jpg link to sample data https://www.filedropper.com/latlondatloctestforstack_1
library(readr)
library(dplyr)
library(tibble)
library(lubridate)
latlntable<- read_csv("latlondatloctestforstack.csv")
latlntable$Month<-format(latlntable$Date, "%Y-%m")
library(ggplot2)
library(maps)
library(ggthemes)
library(gganimate)
library('plotly')
world <- ggplot() +
borders("world", colour = "gray85", fill = "gray90") +
theme_map()
ghost <- tibble(
Month = c(as.Date('2018-06-01',format="%Y-%m-%d")),#'0',#playing with sort by Month
optrad = 0, lon = 0, lat = 0) %>%
mutate(Month = format(Month, "%Y-%m"))
mapn <- world +
geom_point(aes(x = lon, y = lat, size = optrad, # this is the init transparent frame, optrad is the radius of points
frame = Month),
data = ghost, alpha = 0) +
#this is my data
geom_point(position=position_jitter(h=0.005, w=0.005),aes(x = lon, y = lat,
size = optrad,Name=Name,Date=Date,frame=Month,cumulative = TRUE,group=seq_along(Month)),#,frame=date,
data = latlntable, colour = 'purple', alpha = .7) +
scale_radius(range = c(1, 3), breaks = c(10,15,20)) +
ggtitle("MyMapTitle")+
theme(plot.title = element_text(hjust = 0.5,size=35),legend.position = "none")
#all below is for interactive html page through plotly using ggplotly
xp<-ggplotly(mapn, tooltip = c('text','Name','Date'))
p <- xp %>%
animation_opts(
1000,650, easing = "sin", redraw = FALSE,
)
p <- p %>%
layout(xaxis = list(autorange = TRUE,title = "Fixed lat/lon coords displayed",size=10),
yaxis = list(autorange = TRUE),
updatemenus = list(
list(
type = 'buttons',
direction = 'right',
x=0,
y=0,
showactive = FALSE,
buttons = list(list(
label = 'Pause',
method = 'animate',
args = list(NULL, list(fromcurrent = TRUE, mode = "immediate"), NULL)
)))))
p <- p %>% config(displaylogo = FALSE,
modeBarButtonsToRemove = list(
'sendDataToCloud',
'toImage',
'resetScale2d',
'hoverClosestCartesian',
'hoverCompareCartesian',
'lasso2d',
'select2d',
'toggleSpikelines'
))
animation_slider(p, hide = FALSE)