探索适合网页的功能
让我们将 plotly 用在另一幅图上,并探索其交互功能。
本练习是课程的一部分
使用 flexdashboard 构建仪表板
练习说明
- 直接 Knit 当前代码,展开 HTML 查看器,并检查生成的图形。
- 使用
ggplotly(),让 Station Usage 图表中的station_gg图在网页上更友好。 - 再次 Knit 并展开,以便开始探索。
交互式实操练习
通过完成这段示例代码来试试这个练习。
{"my_document.Rmd":"---\ntitle: \"Bike Shares Daily\"\noutput: \n flexdashboard::flex_dashboard:\n orientation: columns\n vertical_layout: fill\n---\n\n```{r setup, include=FALSE}\nlibrary(flexdashboard)\nlibrary(readr)\nlibrary(lubridate)\nlibrary(ggplot2)\nlibrary(tidyverse)\nlibrary(plotly)\n\ntrips_df <- read_csv('https://assets.datacamp.com/production/course_6355/datasets/sanfran_bikeshare_joined_oneday.csv')\n```\n\nColumn \n-----------------------------------------------------------------------\n\n### Station Usage\n\n```{r}\n\nstation_df <- trips_df %>%\n select(start_station_name, end_station_name) %>%\n rename(Start = start_station_name, End = end_station_name) %>%\n pivot_longer(cols = Start:End, names_to = 'Usage', values_to = 'Station')\n\nstation_gg <- ggplot(station_df,\n aes(x = Station, fill = Usage)) +\n geom_bar(position = 'stack') +\n theme_bw() +\n ylab('Trips') +\n xlab('') +\n theme(axis.text.x = element_text(angle = 45, hjust = 1))\n \nstation_gg \n\n```\n\n\n"}