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

以下是数据:

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()

enter image description here

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

推荐答案

group = datetime:

(我增加了fps只是为了reprex.

library(gganimate)

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

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

创建于2024—03—29,reprex v2.1.0

R相关问答推荐

是否可以 Select 安装不带文档的R包以更有效地存储?

对lme 4对象运行summary()时出错(diag中的错误(from,names = RST):对象unpackedMatrix_diag_get找不到)

如何删除R中除某些特定名称外的所有字符串?

derrr mutate case_when grepl不能在R中正确返回值

我想在R中总结一个巨大的数据框架,使我只需要唯一的lat、lon、Date(Year)和Maxium Value""""""""

未识别时区

使用整齐的计算(curl -curl )和杂音

R中的时间序列(Ts)函数计数不正确

如何使用ggplot对堆叠条形图进行嵌套排序?

如何在R forestplot中为多条垂直线分配唯一的 colored颜色 ?

迭代到DataFrame列并获得成对的值列表(col1->;col2、col2->;col3、col3->;col4等)的正确方法.

使用带有OR条件的grepl过滤字符串

使用Scale_*_MANUAL时在图例中保留未使用的系数级别

安全地测试文件是否通过R打开

基于Key->Value数据帧的基因子集相关性提取

Geom_arcbar()中出错:找不到函数";geom_arcbar";

变长向量的矢量化和

如何根据未知数的多列排除重复行

如何在R中创建这些列?

如何在shiny 的应用程序 map 视图宣传单中可视化单点