交互式图表允许用户进行操作:如缩放、悬停以获得工具提示、选择要显示的变量等等。R提供了一组称为html部件的包:可以直接从R中建立交互式数据图表。
交互式气泡图代码
# R 包加载
> library(ggplot2)
> library(plotly)
# 数据设置
> library(gapminder)
# 绘制交互式气泡图
> bbuble <- gapminder %>%
+ filter(year==1977) %>%
+ ggplot( aes(gdpPercap, lifeExp, size = pop, color=continent)) +
+ geom_point() +
+ theme_bw()
> ggplotly(bbuble)
OUTPUT: