{"action":"created","issue":{"url":"https://api.github.com/repos/gingi99/HowToR/issues/8","repository_url":"https://api.github.com/repos/gingi99/HowToR","labels_url":"https://api.github.com/repos/gingi99/HowToR/issues/8/labels{/name}","comments_url":"https://api.github.com/repos/gingi99/HowToR/issues/8/comments","events_url":"https://api.github.com/repos/gingi99/HowToR/issues/8/events","html_url":"https://github.com/gingi99/HowToR/issues/8","id":359036826,"node_id":"MDU6SXNzdWUzNTkwMzY4MjY=","number":8,"title":"plotly","user":{"login":"gingi99","id":1721212,"node_id":"MDQ6VXNlcjE3MjEyMTI=","avatar_url":"https://avatars2.githubusercontent.com/u/1721212?v=4","gravatar_id":"","url":"https://api.github.com/users/gingi99","html_url":"https://github.com/gingi99","followers_url":"https://api.github.com/users/gingi99/followers","following_url":"https://api.github.com/users/gingi99/following{/other_user}","gists_url":"https://api.github.com/users/gingi99/gists{/gist_id}","starred_url":"https://api.github.com/users/gingi99/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gingi99/subscriptions","organizations_url":"https://api.github.com/users/gingi99/orgs","repos_url":"https://api.github.com/users/gingi99/repos","events_url":"https://api.github.com/users/gingi99/events{/privacy}","received_events_url":"https://api.github.com/users/gingi99/received_events","type":"User","site_admin":false},"labels":[{"id":1051117233,"node_id":"MDU6TGFiZWwxMDUxMTE3MjMz","url":"https://api.github.com/repos/gingi99/HowToR/labels/visualization","name":"visualization","color":"d93f0b","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-09-11T13:01:06Z","updated_at":"2018-09-15T13:57:11Z","closed_at":null,"author_association":"OWNER","body":"#### インストール\r\n```R\r\n> devtools::install_github(\"ropensci/plotly\")\r\n```\r\n\r\n#### Plotly基礎\r\n```R\r\nplot_ly(iris, x = ~Petal.Length, y = ~Petal.Width,\r\n          color = ~Sepal.Length>6, colors = c(\"#132B43\", \"#56B1F7\"))\r\n```\r\n\r\n#### サンプルデータ\r\n```R\r\n> txhousing\r\n# A tibble: 8,602 x 9\r\n   city     year month sales   volume median listings inventory  date\r\n   <chr>   <int> <int> <dbl>    <dbl>  <dbl>    <dbl>     <dbl> <dbl>\r\n 1 Abilene  2000     1    72  5380000  71400      701       6.3 2000 \r\n 2 Abilene  2000     2    98  6505000  58700      746       6.6 2000.\r\n 3 Abilene  2000     3   130  9285000  58100      784       6.8 2000.\r\n 4 Abilene  2000     4    98  9730000  68600      785       6.9 2000.\r\n 5 Abilene  2000     5   141 10590000  67300      794       6.8 2000.\r\n 6 Abilene  2000     6   156 13910000  66900      780       6.6 2000.\r\n 7 Abilene  2000     7   152 12635000  73500      742       6.2 2000.\r\n 8 Abilene  2000     8   131 10710000  75000      765       6.4 2001.\r\n 9 Abilene  2000     9   104  7615000  64500      771       6.5 2001.\r\n10 Abilene  2000    10   101  7040000  59300      764       6.6 2001.\r\n# ... with 8,592 more rows\r\n```\r\n\r\n#### Filterする方法\r\n```R\r\n> txhousing %>% filter(city %in% c(\"Tyler\",\"Victoria\")) %>% plot_ly(x = ~date, y = ~median, showlegend = FALSE) %>% add_lines(color = ~city, colors = \"black\")\r\n```\r\n\r\n#### highlightする方法\r\n```R\r\n> tx <- highlight_key(txhousing, ~city)\r\n> tx %>% plot_ly(x = ~date, y = ~median, showlegend = FALSE) %>% add_lines(color = ~city, colors = \"black\") -> p\r\n> highlight(p, on = NULL, color = NULL, selectize = F, defaultValues = c(\"Tyler\",\"Victoria\"))\r\n```\r\n\r\n#### クリックしたイベントを削除\r\nhttps://stackoverflow.com/questions/42996303/removing-plotly-click-event-data\r\n\r\n#### 参考\r\n- Github：https://github.com/ropensci/plotly\r\n- Reference ：https://plot.ly/r/reference/"},"comment":{"url":"https://api.github.com/repos/gingi99/HowToR/issues/comments/421574551","html_url":"https://github.com/gingi99/HowToR/issues/8#issuecomment-421574551","issue_url":"https://api.github.com/repos/gingi99/HowToR/issues/8","id":421574551,"node_id":"MDEyOklzc3VlQ29tbWVudDQyMTU3NDU1MQ==","user":{"login":"gingi99","id":1721212,"node_id":"MDQ6VXNlcjE3MjEyMTI=","avatar_url":"https://avatars2.githubusercontent.com/u/1721212?v=4","gravatar_id":"","url":"https://api.github.com/users/gingi99","html_url":"https://github.com/gingi99","followers_url":"https://api.github.com/users/gingi99/followers","following_url":"https://api.github.com/users/gingi99/following{/other_user}","gists_url":"https://api.github.com/users/gingi99/gists{/gist_id}","starred_url":"https://api.github.com/users/gingi99/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gingi99/subscriptions","organizations_url":"https://api.github.com/users/gingi99/orgs","repos_url":"https://api.github.com/users/gingi99/repos","events_url":"https://api.github.com/users/gingi99/events{/privacy}","received_events_url":"https://api.github.com/users/gingi99/received_events","type":"User","site_admin":false},"created_at":"2018-09-15T13:57:11Z","updated_at":"2018-09-15T13:57:11Z","author_association":"OWNER","body":"#### サイドバーに選択画面だして、Plotlyで表示の例\r\n\r\n```R\r\nlibrary(plotly)\r\nlibrary(crosstalk)\r\n\r\n<snip>\r\n\r\ndf.highlight <- highlight_key(df.rlib.series, ~lib_name)\r\n\r\n#p <- ggplot(df.highlight) + \r\n#  geom_point(aes(x = date, y = count, group = lib_name, color = lib_name, text = paste0(lib_name,\":\",count)), size = 1, shape = 21) +\r\n#  geom_line(aes(x = date, y = count, group = lib_name, color = lib_name, text = paste0(lib_name,\":\",count))) +\r\n#  theme(legend.position = 'none') # plotly で color の判例消すやつ\r\n#gg <- ggplotly(p, tooltip = \"text\")\r\n\r\ngg <- plot_ly(df.highlight, x = ~date, y = ~count_cum, showlegend = FALSE) %>% \r\n  add_lines(color = ~lib_name) %>%\r\n  layout(xaxis = list(title = \"日付（半年ごと)\"), yaxis = list(title = \"カウント\"))\r\n\r\n# sidebar\r\nwidgets <- bscols(\r\n  widths = c(12),\r\n  filter_select(\"lib\", \"library\", df.highlight, ~lib_name)\r\n)\r\n\r\n# main\r\nbscols(\r\n  widths = c(2, 10), \r\n  widgets, \r\n  gg\r\n)\r\n```"}}
{"actor":{"display_login":"gingi99"}}