R Plotly 动画图表仅显示初始帧中包含数据的组
R Plotly animated chart only showing groups with data in initial frame
我正在尝试在 R 中使用 plotly 创建动画气泡图,但我 运行 遇到了一个特别困难的问题。
library(plotly)
dates <- 2000:2010
countries <- c("US", "GB", "JP")
df <- merge(dates, countries, all=TRUE)
names(df) <- c("Date", "Country")
df$x <- rnorm(nrow(df))
df$y <- rnorm(nrow(df))
df[1:3, c("x", "y")] <- NA
p <- plot_ly(df, x=~x, y=~y, color=~Country, frame=~Date, type="scatter", mode="markers")
p
由于美国前 3 年的缺失值,生成的图根本不包括美国的点,即使美国有数据的年份也是如此。
Screenshot of resulting chart
我不知道如何用 plotly
修复它,但如果你对 ggplotly
没问题,它似乎可以解决问题:
p <- ggplot(df, aes(x, y, color = Country)) +
geom_point(aes(frame = Date)) + theme_bw()
ggplotly(p)
我正在尝试在 R 中使用 plotly 创建动画气泡图,但我 运行 遇到了一个特别困难的问题。
library(plotly)
dates <- 2000:2010
countries <- c("US", "GB", "JP")
df <- merge(dates, countries, all=TRUE)
names(df) <- c("Date", "Country")
df$x <- rnorm(nrow(df))
df$y <- rnorm(nrow(df))
df[1:3, c("x", "y")] <- NA
p <- plot_ly(df, x=~x, y=~y, color=~Country, frame=~Date, type="scatter", mode="markers")
p
由于美国前 3 年的缺失值,生成的图根本不包括美国的点,即使美国有数据的年份也是如此。
Screenshot of resulting chart
我不知道如何用 plotly
修复它,但如果你对 ggplotly
没问题,它似乎可以解决问题:
p <- ggplot(df, aes(x, y, color = Country)) +
geom_point(aes(frame = Date)) + theme_bw()
ggplotly(p)