我的数据框看起来像这样:
ID V1 V2 V3
1 1 2 3
1 2 3 4
1 3 4 5
2 3 4 5
3 4 5 6
3 2 3 4
Run Code Online (Sandbox Code Playgroud)
我需要重塑数据框,以便所有记录属于同一行中的一个人,如下所示:
ID V1 V2 V3 V1_2 V2_2 V3_2 V1_3 V2_3 V3_3
1 1 2 3 2 3 4 3 4 5
2 3 4 5
3 4 5 6 2 3 4
Run Code Online (Sandbox Code Playgroud)
因为每个人具有不同数量的记录,所以新数据框在每行中具有不同的长度.我怎样才能做到这一点?
我正在尝试在地图上累计绘制每个月打开的新位置。我可以每月创建一个包含新位置的动画,但不能累积。换句话说,我希望看到新地点添加到现有地点。
这是示例数据
DF <- data.frame("latitude" = c(42.29813,41.83280,41.83280,30.24354),
"longitude" =c(-71.23154,-72.72642,-72.72642,-81.62098),
"month" = c(1,2,3,4))
Run Code Online (Sandbox Code Playgroud)
这是我尝试过的
usa <- ggplot() +
borders("usa", colour = "gray85", fill = "gray80") +
theme_map()
map <- usa +
geom_point(aes(x = longitude, y = latitude, cumulative=TRUE,
frame=month,stat = 'identity' ),data = DF )
map
# Generate the Visual and a HTML output
ggp <- ggplotly(map)%>%
animation_opts(transition = 0)
ggp
Run Code Online (Sandbox Code Playgroud)
输出不累计显示位置。基本上我想最后看到所有四个地点。