R语言与医学统计图形-【31】动态交互绘图
1.plotly包
动态散点图
library(plotly) # 交互散点图 plot_ly(data=iris, x=~Sepal.Length, y=~Petal.Length, marker=list(size=10, color='rgba(255,182,193,.9)', line=list(color='rgba(152,0,0,.8)', width=2))) %>% layout(title='Styled Scatter', yaxis=list(zeroline=FALSE), xaxis=list(zeroline=FALSE)) #多维数据,添加标签 plot_ly(mpg,x=~hwy,y=~displ,color=~factor(cyl), text=~paste('Model:',model)) %>% layout(title='MPG data',font=list(family='Times New Roman', size=13,color='forestgreen')) #参数 plot_ly(data=iris,x=~Sepal.Length,y=~Petal.Length, type = 'scatter',#lines/markers/text/none mode='makers', symbol = ~Species, #点类型 symbols = c('circle','x','o'),color = I('black'), marker=list(size=10))
#点连线形式 trace0 <- rnorm(100,mean=5) trace1 <- rnorm(100,mean=0) trace2 <- rnorm(100,mean=-5) x <- c(1:100) data <- data.frame(x,trace0,trace1,trace2) #第一张散点图以线图形式展示 plot_ly(data,x=~x,y=~trace0, name = 'trace 0',type = 'scatter', mode='lines') %>% #第二张以点连线形式展示 add_trace(y=~trace1,name='trace 1', mode='lines+markers') %>% #第三张普通散点图 add_trace(y=~trace2,name='trace 2', mode='markers') %>% layout(xaxis=list(zeroline=FALSE)) #add_trace/add_histogram/add_boxplot/add_text
其他动态图
#动态气泡图 # 动态线图 # 动态条形图 # 动态直方图 # 动态盒形图 # 动态误差条图 # 动态饼图和戒指图
2. recharts包
接近基础绘图语法。
散点图
#devtools::install_github('taiyun/recharts') library(recharts) #散点图 ePoints(iris[,3:5],series = ~Species) ePoints(iris[,3:5], xvar=~Petal.Length, yvar=~Petal.Width, series = ~Species, xlab.name = 'Petal Length', ylab.name = 'Petal Width', xlab.namePosition = 'end', ylab.namePosition = 'end', title = 'IRIS data', title.x = 'center', title.y = 'top', legend.orient = 'vertical', legend.x = 'right', legend.y = 'center')
其他动态图
#线图 names(mtcars) eLine(mtcars,xvar = ~cyl,yvar = ~mpg,series = ~gear) #条形图 eBar(mtcars,xvar = ~cyl,yvar = ~mpg,series = ~gear) #饼图 x=runif(6) names(x)=LETTERS[1:6] ePie(x,type='pie',title = 'PIE') #玫瑰图 ePie(x,type = 'rose',roseType = 'radias',title = 'Rose plot') #雷达图 eRadar(mtcars,xvar = ~cyl,yvar = ~mpg,series = ~gear) #漏斗图、面积图等。。。
3. rChart包
语法近似于lattice绘图系统。在R中实现Polychart、Morris、NVD3等多个js绘图库。
https://github.com/ramnathv/rCharts
没安装上
Ploychart
4.threejs包
3D显示功能。
#install.packages('threejs') library(threejs) #三维散点图 N <- 100 i <- sample(3,N,replace = TRUE) x <- matrix(rnorm(N*3),ncol=3) lab <- c('small','bigger','biggest') scatterplot3js(x,color = rainbow(N),labels=lab[i], size=i,renderer = "canvas") #三维地图 library(maps) data("world.cities",package = 'maps') cities <- world.cities[order(world.cities$pop,decreasing = TRUE)[1:1000],] value <- 100*cities$pop/max(cities$pop) col <- colorRampPalette(c('cyan','lightgreen'))(10)[floor(10*value/100)+1] threejs::globejs(lat = cities$lat, long=cities$long, value=value, color = col, atmosphere = TRUE)
5.timevis包
#绘制动态时间轴,展示时间节点事件 library(timevis) timevis(data.frame(id=1:3, content=c('one','two','three'), start=c('2016-01-10','2016-01-14','2016-01-19'), end=c(NA,'2016-01-18',NA), type=c('point','background','box')))
6.dygraphs包
#动态时间序列 library(dygraphs) lungDeaths <- cbind(mdeaths,fdeaths) dygraph(lungDeaths) #选择特定时间 dygraph(lungDeaths) %>% dyRangeSelector(dateWindow = c('1975-06-01','1978-12-31'))
7.leaflet包
js开源交互式地图包,在R中利用哦html5显示。
#install.packages('leaflet') library(leaflet) f <- leaflet() #初始化 y <- addTiles(f) #调用地图底图 addMarkers(y, lng = 121.445, lat=31.1980, popup = '复旦大学上海医学院') #添加标记 #用管道符 leaflet() %>% addTiles() %>% addMarkers(lng = 121.445,lat = 31.1980,popup = '复旦大学医学院')
功能强大,不再演示。
相关推荐
cyydjt 2020-05-16
HongKongPython 2020-01-03
数据齿轮 2019-12-10
oXiRiShi 2019-10-26
阿文alvin 2014-05-30
bernin 2014-05-29
solarLan 2019-06-28
wuShiJingZuo 2011-01-26
一个人的村庄 2010-12-14
tianxiaolu 2010-03-29
LadyZhong 2013-03-01
lrxcmwy 2012-11-05
maiktom 2012-08-30
wes0 2006-11-12
SusanXu 2011-05-05
CSDN版 2015-07-31
naokea 2012-03-25
njhhack 2018-07-12