[问题] plotly套件画图-调整标记

楼主: open272 (好ㄘ的肉)   2016-12-12 21:39:35
[问题类型]:
程式咨询
[软件熟悉度]:
入门(写过其他程式,只是对语法不熟悉)
[问题叙述]:
利用plotly套件画bar plot时,要调整bar标注时发现找不到准确的X轴位置对应到相对
应的bar中心,参考下图
http://imgur.com/y8sUzSM
[程式范例]:
library(plotly)
Animals <- c("giraffes", "orangutans", "monkeys")
SF_Zoo <- c(20, 14, 23)
LA_Zoo <- c(12, 18, 29)
data <- data.frame(Animals, SF_Zoo, LA_Zoo)
y <- c(20,12,14,18,23,29)
p <- plot_ly(data, x = Animals, y = SF_Zoo, type = 'bar', name = 'SF Zoo') %>%
add_trace(y = LA_Zoo, name = 'LA Zoo') %>%
layout(yaxis = list(title = 'Count'), barmode = 'group',
annotations = list( x =data$Animals,y = y, text = y,
xanchor = 'center', yanchor = 'bottom',
showarrow = FALSE))
[环境叙述]:
R version 3.2.5 Patched (2016-05-05 r70791)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.12.1 (unknown)
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] RJDBC_0.2-5 rJava_0.9-8 DBI_0.4-1 corrplot_0.77
[6] RColorBrewer_1.1-2 googlesheets_0.2.0 gridExtra_2.2.1 plotly_4.5.2
[11] sp_1.2-3 ggplot2_2.1.0 DT_0.2 stringr_1.0.0
[16] tidyr_0.4.1 dplyr_0.4.3
loaded via a namespace (and not attached):
[1] Rcpp_0.12.6 cellranger_1.0.0 plyr_1.8.4 base64enc_0.1-3 t
oo
[6] digest_0.6.10 evaluate_0.9 jsonlite_1.1 tibble_1.2 g
ta
[11] lattice_0.20-33 viridisLite_0.1.3 yaml_2.1.13 parallel_3.2.5 k
ni
[16] httr_1.1.0 htmlwidgets_0.7 gtools_3.5.0 grid_3.2.5 R
6_
[21] rmarkdown_1.0 foreign_0.8-66 purrr_0.2.1 magrittr_1.5 s
ca
[26] htmltools_0.3.5 assertthat_0.1 colorspace_1.2-6 stringi_1.1.1 l
az
[31] munsell_0.4.3
[关键字]:
plotly , 视觉化
作者: clansoda (小笨)   2016-12-12 21:46:00
疴,我有点看不懂叙述,我看你的X轴的值蛮正的阿你是要说你的那几个数字吗?我不清楚plotly的写法所以我提供一下ggplot的写法+ geom_text(label = 你要放上去的值, h_just = 用来调整的argument,你写完ggplot以后 最后用ggplotly可以得到跟plotly一样的结果,仅供参考,plotly的需要其他人来提供

Links booklink

Contact Us: admin [ a t ] ucptt.com