gganimate 在使用 Shadow_mark 选项时不会保留所有过去的标记

问题描述 投票:0回答:1

我正在绘制地震图,我想展示地震位置如何随时间变化。我只想看到随着时间的推移绘制的地震位置点,而不是地震位置之间的移动点(因为它似乎正在发生)。

这些是数据:

clust <- data.frame(latitude = c(31.61205, 31.6132, 31.61286, 31.61355, 
31.61087, 31.6141, 31.61514, 31.6132, 31.61118, 31.61511, 31.61409, 
31.61409, 31.61307, 31.618, 31.60965, 31.61007, 31.60884, 31.60905, 
31.6094, 31.60816, 31.61068, 31.61006, 31.60837, 31.61254, 31.60817, 
31.61333, 31.60954, 31.61123, 31.61157, 31.60904, 31.60845), 
    longitude = c(-104.53083, -104.52606, -104.52635, -104.5249, 
    -104.53191, -104.52602, -104.52617, -104.52593, -104.5309, 
    -104.52869, -104.52988, -104.52938, -104.52963, -104.52836, 
    -104.53803, -104.53386, -104.53954, -104.5379, -104.53699, 
    -104.54104, -104.53371, -104.53538, -104.54168, -104.52697, 
    -104.54457, -104.53882, -104.53805, -104.53255, -104.52933, 
    -104.54067, -104.54229), depth = c(7.589, 7.295, 7.387, 7.282, 
    7.454, 7.76, 7.787, 7.282, 7.675, 6.003, 6.077, 6.126, 6.218, 
    7.494, 7.026, 7.59, 7.623, 7.545, 7.287, 7.693, 7.169, 7.423, 
    7.65, 7.066, 7.137, 8.316, 7.129, 7.41, 7.477, 7.115, 7.16
    ), mag = c(3.12, 2.64, 2.5, 2.34, 2.63, 1.44, 1.47, 2.27, 
    2.28, 2.14, 2.31, 2.26, 2.2, 2.04, 2.32, 2.12, 2.6, 2.16, 
    3.02, 2.04, 3.31, 2.28, 2.1, 2.26, 2.74, 2, 2.01, 2.83, 2.12, 
    2.25, 2.46), cluster = c(11L, 11L, 11L, 11L, 11L, 11L, 11L, 
    11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 
    11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L
    ), datetime = structure(c(1648096488, 1648154064, 1648223479, 
    1648458486, 1648597348, 1650278472, 1650281886, 1653753093, 
    1653814043, 1655618186, 1658076718, 1658093072, 1659482037, 
    1662994538, 1669204899, 1669779205, 1670032484, 1670032691, 
    1670071292, 1670077497, 1670088406, 1670093402, 1670131993, 
    1670147329, 1670688840, 1670766002, 1670942474, 1672311253, 
    1672366539, 1679225056, 1679256690), class = c("POSIXct", 
    "POSIXt"), tzone = "UTC"))

这是我的代码:

anim <- ggplot(clust , aes(x = longitude, y=latitude, size = mag, colour = '#562486')) +
  geom_point(show.legend = FALSE, alpha = 0.7) +
  scale_color_viridis_d() +
  theme_bw() +
  labs(x = "Longitude", y = "Latitude") + 
  transition_time(clust$datetime) +
  labs(title = "{frame_time}") +
  shadow_mark(past = TRUE, future = FALSE, alpha = 0.5) 

animate(anim,  height = 4, width = 7, units = "in", fps = 0.5, end_pause = 60, res = 100) #+ gifski_renderer()

我尝试过

transition_events(start = datetime)
而不是
transition_time(clust$datetime)
,但我不太了解这些选项,所以这给了我错误。我也尝试过调整wake_length的shadow_mark选项,但我不确定是否还有其他我不知道的选项。

r ggplot2 gganimate
1个回答
0
投票
library(gganimate)
#> Loading required package: ggplot2

anim <- ggplot(clust , aes(x = longitude, y=latitude, 
                           size = mag, colour = '#562486',
                           group = datetime)) +
  geom_point(show.legend = FALSE, alpha = 0.7) +
  scale_color_viridis_d() +
  theme_bw() +
  labs(x = "Longitude", y = "Latitude") + 
  transition_time(clust$datetime) +
  labs(title = "{frame_time}") +
  shadow_mark(past = TRUE, future = FALSE, alpha = 0.5) 

animate(anim,  height = 4, width = 7, units = "in", fps = 0.5, end_pause = 60, res = 100)

创建于 2024-03-28,使用 reprex v2.0.2

© www.soinside.com 2019 - 2024. All rights reserved.