R GG使用geom_栏设置动画问题?
自从大卫·罗宾逊(David Robinson)发布了他的gganimate软件包并认为我自己也会有一个剧本以来,我一直在羡慕和钦佩twitter上出现的各种ggplot动画。我在使用geom_栏时遇到gganimate问题。希望下面的示例能够说明这个问题 首先为可再现的示例生成一些数据:R GG使用geom_栏设置动画问题?,r,ggplot2,gganimate,R,Ggplot2,Gganimate,自从大卫·罗宾逊(David Robinson)发布了他的gganimate软件包并认为我自己也会有一个剧本以来,我一直在羡慕和钦佩twitter上出现的各种ggplot动画。我在使用geom_栏时遇到gganimate问题。希望下面的示例能够说明这个问题 首先为可再现的示例生成一些数据: df <- data.frame(x = c(1, 2, 1, 2), y = c(1, 2, 3, 4), z = c("A", "
df <- data.frame(x = c(1, 2, 1, 2),
y = c(1, 2, 3, 4),
z = c("A", "A", "B", "B"))
但是当我使用GG动画时,B的情节表现得很奇怪。在第二帧中,条从第一帧的条结束时的值开始,而不是从原点开始。就像是一个堆叠的条形图
p <- ggplot(df, aes(x = x, y = y, frame = z)) +
geom_bar(stat = "Identity")
gg_animate(p)
我试图发布一些图片,但显然我没有足够的声誉,所以我希望没有这些图片是有意义的。这是一个错误,还是我遗漏了什么
提前感谢,
托马斯(Thomas)原因是,如果没有刻面,钢筋是堆叠的。使用
position=“identity”
:
当您将
fill
替换为frame
时,绘制的两个绘图正好对应于一次只绘制一种颜色。谢谢,这很有意义!
p <- ggplot(df, aes(x = x, y = y, frame = z)) +
geom_bar(stat = "Identity")
gg_animate(p)
q <- ggplot(df, aes(x = x, y = y, frame = z)) +
geom_point()
gg_animate(q)
p <- ggplot(df, aes(x = x, y = y, frame = z)) +
geom_bar(stat = "Identity", position = "identity")
gg_animate(p)
p <- ggplot(df, aes(x = x, y = y, fill = z)) +
geom_bar(stat = "Identity")
p