作者celestialgod (攸蓝)
看板R_Language
标题Re: [问题] 在shiny上以rCharts画scatter plot
时间Sun Jul 26 15:13:08 2015
7/26 16:23更新:
後来测试成功,重点在於设定dom的名称
code:
http://pastebin.com/6c0gdc1Y
nPlot成功案例:
http://tinyurl.com/ovuxmpt
7/26 15:10写的:
我跑是没出现任何警告跟错误,我的环境列於下方:
而且有正常呈现,不过你的scatter_plot那个tab没有图就是
> sessionInfo()
R version 3.2.0 (2015-04-16)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=Chinese (Traditional)_Taiwan.950
[2] LC_CTYPE=Chinese (Traditional)_Taiwan.950
[3] LC_MONETARY=Chinese (Traditional)_Taiwan.950
[4] LC_NUMERIC=C
[5] LC_TIME=Chinese (Traditional)_Taiwan.950
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] shiny_0.11.1 rCharts_0.4.5
loaded via a namespace (and not attached):
[1] R6_2.0.1 plyr_1.8.2 htmltools_0.2.6 tools_3.2.0
[5] whisker_0.3-2 yaml_2.1.13 Rcpp_0.11.5 RJSONIO_1.3-0
[9] grid_3.2.0 digest_0.6.8 xtable_1.7-4 httpuv_1.3.2
[13] mime_0.3 lattice_0.20-31
测试code:
http://pastebin.com/qxpRSm0y
(我只是把ui.R跟server.R合并到function而已)
※ 引述《ardodo (米虫)》之铭言:
: [问题类型]:
:
: 程式谘询(我想用R 做某件事情,但是我不知道要怎麽用R 写出来)
:
: [软体熟悉度]:
: 请把以下不需要的部份删除
: 入门(写过其他程式,只是对语法不熟悉)
:
: [问题叙述]:
: 版友好,我试着以rCharts在shiny上绘制iris的散布图,但是画不出来,不知道为什麽
: code在此 http://pastebin.com/EkS2YxcC
: 执行shiny後,会跳出以下的讯息:
: Note: the specification for S3 class “AsIs” in package ‘jsonlite’ seems
: equivalent to one from package ‘RJSONIO’: not turning on duplicate class
: definitions for this class.
: 恳请解答,感谢
: 附上我的sessionInfo
: other attached packages:
: [1] rCharts_0.4.5 shiny_0.12.1
: loaded via a namespace (and not attached):
: [1] Rcpp_0.11.6 lattice_0.20-31 digest_0.6.8 mime_0.3
: grid_3.2.1
: [6] R6_2.1.0 plyr_1.8.3 xtable_1.7-4 jsonlite_0.9.16
: rstudioapi_0.3.1
: [11] whisker_0.3-2 RJSONIO_1.3-0 tools_3.2.1 httpuv_1.3.2
: yaml_2.1.13
: [16] rsconnect_0.4.1.2 htmltools_0.2.6
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 123.205.27.107
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/R_Language/M.1437894791.A.4C4.html
1F:推 ardodo: 感谢版主的回文,看起来rCharts的不同套件功能如hPlot, 07/27 11:44
2F:→ ardodo: rPlot, nPlot在设定上略有不同,而重点就是dom要指名 07/27 11:45
3F:→ ardodo: 不晓得哪里有rCharts底下各种图的用法说明文件? 07/27 11:45
4F:→ ardodo: 我找了好久只找到rCharts Documentation比较完整 07/27 11:46
5F:→ ardodo: 想知道如何设定图形大小、margin等图形参数 07/27 11:47
我也仔细去查过了,rCharts只有examples
你要修正rCharts,只能去看他们只使用的library,然後去做修改
你在rCharts的github可以看到相关的叙述
rCharts supports multiple javascript charting libraries, each with its own
strengths. Each of these libraries has multiple customization options, most
of which are supported within rCharts. More documentation is underway on how
to use rCharts with each of these libraries.
所以细部设定的文件都还在写,不过你那些js library的选项大都有支援
因此,你可以尝试去查那些js library做参数修改
6F:推 ardodo: 原来如此,所以就是要查看看这些rCharts支援的js library 07/27 12:04
7F:→ ardodo: 是怎麽设定图形的罗?感谢回答 07/27 12:04
举例来说,我要改chart一些参数,你可以从nvd3找到
透过chart这个函数你可以去设定他的参数(这部分我直接去翻source code)
library(rCharts)
h = 600
w = 600
padding = 40
n1 = nPlot(Sepal.Length ~ Sepal.Width, data = iris, group = "Species",
type = "scatterChart")
xlim = range(iris$Sepal.Width)
xlim = xlim * c(0.95, 1.05) + diff(xlim) * c(-0.1, 0.1)
ylim = range(iris$Sepal.Length)
ylim = ylim * c(0.95, 1.05) + diff(ylim) * c(-0.1, 0.1)
n1$chart(xRange = c(0, w - padding),
yRange = c(h-padding*2, padding),
xDomain = xlim, yDomain = ylim)
n1$addParams(height = h, width = w)
n1
这里xRange, xDomain这些都来自d3.js的 d3.scale.range跟 d3.scale.domain
如果没有这个相关知识,你可能很难去做这方面的调整
这个已经超出R版范围,我帮助也有限
而且我也只是之前稍微研究过d3.js,我没办法提供太多资讯
8F:推 ardodo: 感谢版主热心的分享,看来这需要学习js才能解决 07/27 13:44
9F:→ ardodo: 太感谢了!!!! 07/27 13:44
你只能期待rCharts作者可以把文件写得更加详细
让R使用者不必知道js也可以做
※ 编辑: celestialgod (123.205.27.107), 07/27/2015 13:49:28