[問題類型]:
程式諮詢(我想用R 做某件事情,但是我不知道要怎麼用R 寫出來)
[軟體熟悉度]:
使用者(已經有用R 做過不少作品)
[問題敘述]:
下方的程式範例直接執行可出現一個互動式圖。
當滑鼠移到線上的時候,在「掛牌日期」那個項目已經從日期被自動轉成數字,
但我想要的是原本日期的樣子(例如2017/07/28)。
我查過資料,知道可以透過下列方法自訂hovertext:
p <- plotly_build(g)
my.text <- paste0("交易種類:", usd$交易種類, "\n",
"掛牌日期:", strftime(usd$掛牌日期, "%Y/%m/%d"), "\n",
"匯率:", usd$匯率)
style(p, text = my.text, hoverinfo = "text", traces = 1:4)
但是這樣畫的顏色與類別對應結果是錯的。
目前遇到的最大問題是:
我不知道我的character vector究竟要用什麼順序,
每一個elements才會順利對到正確的圖上位置。
常常hovertext是改了,但是hovertext文字顯示的交易種類卻跟線的顏色不符。
即使符合了,我也沒有把握數列的順序到底是不是正確的。
或是這種例子有直接用plotly作圖的方法?Thanks in advance!!
已參考過下列文章:
1. R_Language (#1O6p-6pq)
2. https://plot.ly/r/time-series/
3. http://www.r-graph-gallery.com/2017/06/07/get-the-best-from-ggplotly/
[程式範例]:
https://gist.github.com/anonymous/c39f842543e49c5963671e333eb396ab
[環境敘述]:
R version 3.4.0 (2017-04-21)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.6
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib
locale:
[1] zh_TW.UTF-8/zh_TW.UTF-8/zh_TW.UTF-8/C/zh_TW.UTF-8/zh_TW.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] shiny_1.0.3 shinydashboard_0.6.1 reshape2_1.4.2
[4] plotly_4.7.0 ggplot2_2.2.1 magrittr_1.5
[7] rvest_0.3.2 xml2_1.1.1 httr_1.2.1
loaded via a namespace (and not attached):
[1] Rcpp_0.12.11 compiler_3.4.0 plyr_1.8.4
[4] bindr_0.1 tools_3.4.0 digest_0.6.12
[7] evaluate_0.10.1 jsonlite_1.5 tibble_1.3.3
[10] gtable_0.2.0 viridisLite_0.2.0 pkgconfig_2.0.1
[13] rlang_0.1.1 crosstalk_1.0.0 yaml_2.1.14
[16] curl_2.8.1 bindrcpp_0.2 knitr_1.16
[19] dplyr_0.7.2 stringr_1.2.0 htmlwidgets_0.9
[22] rprojroot_1.2 grid_3.4.0 glue_1.1.1
[25] data.table_1.10.4 R6_2.2.2 rmarkdown_1.6
[28] purrr_0.2.2.2 tidyr_0.6.3 selectr_0.3-1
[31] backports_1.1.0 scales_0.4.1 htmltools_0.3.6
[34] assertthat_0.2.0 mime_0.5 colorspace_1.3-2
[37] xtable_1.8-2 httpuv_1.3.5 labeling_0.3
[40] stringi_1.1.5 lazyeval_0.2.0 munsell_0.4.3
[關鍵字]:
ggplot2, plotly, ggplotly, hovertext