始める無料で始める

Web向けの機能を探る

別のグラフで plotly を試して、インタラクティブ機能を見ていきましょう。

この演習はコースの一部です

flexdashboard で作るダッシュボード

コースを見る

演習の手順

  • まずはそのままコードをニットし、HTML ビューアを広げて、生成されたプロットを確認します。
  • ggplotly() を使って、Station Usage チャートの station_gg プロットを Web で扱いやすい形にします。
  • 探索に備えて、もう一度ニットしてビューアを拡大します。

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

{"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"}
コードを編集して実行