開始使用免費開始

探索對網頁友善的功能

讓我們用另一張圖搭配 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"}
編輯並執行程式碼