R 在gganimate中,将已设置动画的条形图上的标签四舍五入?
我想把每个相应条上的标签圈起来。当前,动画处于过渡状态时,会显示许多小数位: 数据:R 在gganimate中,将已设置动画的条形图上的标签四舍五入?,r,ggplot2,gganimate,R,Ggplot2,Gganimate,我想把每个相应条上的标签圈起来。当前,动画处于过渡状态时,会显示许多小数位: 数据: mydf通过scales::number设置标签格式将实现以下功能: library(ggplot2) library(gganimate) library(dplyr) testp <- mydf %>% ggplot(aes(x = -ordering, y = Totals, fill = GEO)) + geom_col(width = 0.8, position = "identit
mydf通过scales::number设置标签格式将实现以下功能:
library(ggplot2)
library(gganimate)
library(dplyr)
testp <- mydf %>% ggplot(aes(x = -ordering, y = Totals, fill = GEO)) +
geom_col(width = 0.8, position = "identity") +
coord_flip() +
geom_text(aes(-ordering, y = 0, label = GEO, hjust = 0)) + # country label
geom_text(aes(-ordering, y = Totals, label = scales::number(Totals, acc = 1), hjust = 0)) + # value label
theme_minimal() +
theme(legend.position = "none", axis.text.y = element_blank(), axis.ticks.y = element_blank()) +
labs(
y = "Offences per thousand inhabitants",
x = "Countries", title = "Crime Data for European Countries {closest_state}"
) +
transition_states(TIME, transition_length = 10, state_length = 14, wrap = FALSE)
testa <- testp +
transition_states(TIME, transition_length = 10, state_length = 14, wrap = FALSE)
animate(testp,
fps = 30, width = 600, height = 500, nframes = 10,
start_pause = 30, end_pause = 30, renderer = gifski_renderer("gganim_test.gif")
)
库(ggplot2)
库(gganimate)
图书馆(dplyr)
testp%ggplot(aes(x=排序,y=总数,fill=GEO))+
几何坐标(宽度=0.8,位置=“标识”)+
coord_flip()+
地理信息文本(aes(-ordering,y=0,label=GEO,hjust=0))+#国家/地区标签
几何图形文本(aes(-ordering,y=Totals,label=scales::number(Totals,acc=1),hjust=0))+#值标签
主题_极小值()+
主题(legend.position=“none”,axis.text.y=element\u blank(),axis.ticks.y=element\u blank())+
实验室(
y=“每千居民的犯罪率”,
x=“国家”,title=“欧洲国家{最近的国家}的犯罪数据”
) +
转换状态(时间,转换长度=10,状态长度=14,换行=FALSE)
种皮
library(ggplot2)
library(gganimate)
library(dplyr)
testp <- mydf %>% ggplot(aes(x = -ordering, y = Totals, fill = GEO)) +
geom_col(width = 0.8, position = "identity") +
coord_flip() +
geom_text(aes(-ordering, y = 0, label = GEO, hjust = 0)) + # country label
geom_text(aes(-ordering, y = Totals, label = scales::number(Totals, acc = 1), hjust = 0)) + # value label
theme_minimal() +
theme(legend.position = "none", axis.text.y = element_blank(), axis.ticks.y = element_blank()) +
labs(
y = "Offences per thousand inhabitants",
x = "Countries", title = "Crime Data for European Countries {closest_state}"
) +
transition_states(TIME, transition_length = 10, state_length = 14, wrap = FALSE)
testa <- testp +
transition_states(TIME, transition_length = 10, state_length = 14, wrap = FALSE)
animate(testp,
fps = 30, width = 600, height = 500, nframes = 10,
start_pause = 30, end_pause = 30, renderer = gifski_renderer("gganim_test.gif")
)