我在ggplot中遇到一个奇怪的问题,动画的初始播放中出现了奇怪的线条(在查看器中,并通过Rstudio保存到HTML页面)。我不知道是什么原因造成的,而且已经困扰了许多天。在程序的初始启动(首次按下播放)后,一切看起来都正确且应有的状态。但是,如果它是第一次按下,或者是第一次打开已保存的html页面,那么我会看到这些奇怪的行。以下是我用于创建此地图的代码,以及指向该问题的视频的链接,因为它是可复制的。只需在r中运行此代码,然后按播放按钮。我在各自的列中使用简单的纬度点,以及可选的半径。列格式为“日期,名称,纬度,经度,optrad”。感谢您提供任何帮助!
链接到示例视频:https://imgur.com/a/eBlZb5L 链接到示例数据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)