如何解决使用ggplotly时定义滑块的平移
我想更改滑块外观的平移。 我的x轴名称很长,因此类似于下面的示例,它们倾斜了90度。
data(gapminder,package = "gapminder")
gg <- ggplot(gapminder,aes(gdpPercap,lifeExp,color = continent)) +
geom_point(aes(size = pop,frame = year,ids = country)) +
scale_x_log10() +
theme(axis.text.x = element_text(angle = 90,vjust = 0.5,hjust=1))
gg <- ggplotly(gg)
我的问题是x轴名称和x轴标题干扰了plotly滑块。因此,我希望使用类似以下内容的滑块外观:
gg <- gg %>% layout(title = "Basic Slider",sliders = list(
pad = list(l = 60,b=100))))
但是我收到错误消息:
Error in p$x$layout$sliders[[vapply(p$x$layout$sliders,is_ani_slider,:
attempt to select less than one element in integerOneIndex
解决方法
您可以通过功能animation_slider
为动画滑块设置样式,并通过animation_button
为按钮设置样式。试试这个:
library(plotly)
data(gapminder,package = "gapminder")
gg <- ggplot(gapminder,aes(gdpPercap,lifeExp,color = continent)) +
geom_point(aes(size = pop,frame = year,ids = country)) +
scale_x_log10() +
theme(axis.text.x = element_text(angle = 90,vjust = 0.5,hjust=1))
gg <- ggplotly(gg)
gg
gg %>%
layout(title = "Basic Slider") %>%
animation_slider(
pad = list(l = 60,b = 100)
) %>%
animation_button(label = "Run")
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。