## 1.设置当前工作目录
setwd("./barplot3d/")
## 2.安装和导入R包
# install.packages("barplot3d")
library(barplot3d)
## 3.R包简介
### 3.1 Description
help(package="barplot3d")
# Package: barplot3d
# Type: Package
# Title: Create 3D Barplots
# Version: 1.0.1
# Authors@R: person("Christopher", "Wardell", email="r@cpwardell.com", role=c("aut","cre"))
# Description: Creates 3D barplots. Includes a function for sequence context plots used in DNA sequencing analysis.
# License: Apache License 2.0 | file LICENSE
# Encoding: UTF-8
# LazyData: true
# Imports: rgl
# RoxygenNote: 6.1.1
# Suggests: knitr, rmarkdown
# VignetteBuilder: knitr
# NeedsCompilation: no
# Packaged: 2019-11-05 03:21:48 UTC; cpw
# Author: Christopher Wardell [aut, cre]
# Maintainer: Christopher Wardell <r@cpwardell.com>
# Repository: CRAN
# Date/Publication: 2019-11-06 15:40:07 UTC
# Built: R 4.0.2; ; 2020-06-27 22:17:10 UTC; windows
### 3.2 Package structure
ls(package:barplot3d)
# [1] "bar3d" "barplot3d" "legoplot3d"
################
## 4.开始测试 ##
################
### 4.1 Two example plots
#### 4.1.1 Something very simple
## Load packages
library(rgl)
## Make a very simple 3D barplot using mostly defaults
?barplot3d
# Adds a 3D bar plot to the current RGL scene
barplot3d(rows=1,cols=5,z=1:5,theta=10,phi=10,alpha = 0.5)
# 参数测试
#@ 参数:alpha透明度调节
barplot3d(rows=1,cols=5,z=1:5,theta=10,phi=10,alpha = 0.9, topcolors = "#078E53")
#@ 参数:topcolors条形图上顶颜色调节
barplot3d(rows=1,cols=5,z=1:5,theta=10,phi=10,alpha = 0.5, topcolors = "#078E53", sidecolors = "#00B2EE")
#@ 参数:linecolors条形图的边线颜色调整
barplot3d(rows=1,cols=5,z=1:5,theta=10,phi=10,alpha = 0.5, topcolors = "#078E53", sidecolors = "#00B2EE", linecolors = "#EE0000")
#@ 参数:theta水平调整3d条形图的角度
barplot3d(rows=1,cols=5,z=1:5,theta=50,phi=10,alpha = 0.5, topcolors = "#078E53", sidecolors = "#00B2EE", linecolors = "#EE0000")
#@ 参数:phi垂直调整3d条形图的角度
barplot3d(rows=1,cols=5,z=1:5,theta=50,phi=50,alpha = 0.5, topcolors = "#078E53", sidecolors = "#00B2EE", linecolors = "#EE0000")
#@ 参数:gridlines决定是否填加条形图的背景网格,T则填加,F则不填加
barplot3d(rows=1,cols=5,z=1:5,theta=50,phi=50,alpha = 0.5, topcolors = "#078E53", sidecolors = "#00B2EE", linecolors = "#EE0000", gridlines = T)
barplot3d(rows=1,cols=5,z=1:5,theta=50,phi=50,alpha = 0.5, topcolors = "#078E53", sidecolors = "#00B2EE", linecolors = "#EE0000", gridlines = F)
#@ 参数:xlabels, Labels for the x axis (must be a vector of names the same length as "cols" parameter).
barplot3d(rows=1,cols=5,z=1:5,theta=50,phi=50,alpha = 0.5, topcolors = "#078E53", sidecolors = "#00B2EE", linecolors = "#EE0000", gridlines = F, xlabels = c("A", "B", "C", "D", "E"))
#@ 参数:ylabels, Labels for the y axis (must be a vector of names the same length as "rows" parameter).
barplot3d(rows=1,cols=5,z=1:5,theta=50,phi=50,alpha = 0.5, topcolors = "#078E53", sidecolors = "#00B2EE", linecolors = "#EE0000", gridlines = F, xlabels = c("A", "B", "C", "D", "E"), ylabels = "value")
#@ 参数:zlabels, Labels for the z axis; add numeric scale to the vertical dimension of the plot (TRUE or FALSE).
barplot3d(rows=1,cols=5,z=1:5,theta=50,phi=50,alpha = 0.5, topcolors = "#078E53", sidecolors = "#00B2EE", linecolors = "#EE0000", gridlines = F, xlabels = c("A", "B", "C", "D", "E"), ylabels = "value", zlabels = F)
#@ 参数:xsub
barplot3d(rows=1,cols=5,z=1:5,theta=60,phi=10,alpha = 0.5, topcolors = "#078E53", sidecolors = "#00B2EE", linecolors = "#EE0000", gridlines = F, xlabels = c("A", "B", "C", "D", "E"), ylabels = "value", zlabels = T, xsub = "Samples")
#@ 参数:ysub
barplot3d(rows=1,cols=5,z=1:5,theta=60,phi=10,alpha = 0.5, topcolors = "#078E53", sidecolors = "#00B2EE", linecolors = "#EE0000", gridlines = F, xlabels = c("A", "B", "C", "D", "E"), ylabels = "value", zlabels = T, xsub = "Samples", ysub = "Molecular Weight[KDa]")
#@ 参数:zsub
barplot3d(rows=1,cols=5,z=1:5,theta=60,phi=10,alpha = 0.5, topcolors = "#078E53", sidecolors = "#00B2EE", linecolors = "#EE0000", gridlines = F, xlabels = c("A", "B", "C", "D", "E"), ylabels = "value", zlabels = T, xsub = "Samples", ysub = "Molecular Weight[KDa]", zsub = "Just Number")
#### 4.1.2 Something more decorative
## Make a prettier 3D barplot with more advanced features
inputdata=round(rnorm(15,10,3))
barplot3d(rows=3,cols=5,z=inputdata,scalexy=5,alpha=0.4,theta=30,phi=50,
topcolors=rainbow(15),xlabels = 1:5,ylabels=LETTERS[1:3],
xsub="Numbers",ysub="Letters",zsub="Count")
#@ 重新构建一个更庞大的3d条形图
big_inputdata <- round(rnorm(100, 50, 2))
barplot3d(rows=10,cols=10,z=big_inputdata,scalexy=5,alpha=0.4,theta=30,phi=50, topcolors=rainbow(100),xlabels = 1:10,ylabels=LETTERS[1:10], xsub="Numbers",ysub="Letters",zsub="Count")
### 4.3 Viewing angles, plot size and saving your plot
# “theta” rotates the viewpoint in the horizontal plane (imagine it on a rotating turntable) and can be set between 0 and 360 degrees.
# “phi” rotates the viewpoint in the vertical plane (imagine going below and above the plot) and can be set between -90 to 90 (-90 is directly below, 90 directly above).
# The 4 arguments are the position (in pixels) of the left, top, right and bottom edges of the rgl viewing window
# This code leads to a plot that is 600 pixels wide and 400 pixels tall.
par3d(windowRect=c(0,50,600,450))
# Save the current rgl view
rgl.snapshot("filename.png")
# Error in rgl.snapshot("filename.png") :
# pixmap save format not supported in this build
### 4.4 Legoplots
# Read in COSMIC signature probabilities
x=system.file("extdata", "signature_probabilities.txt", package = "barplot3d")
sigdata=read.table(x,header=TRUE,stringsAsFactors = FALSE)
# Plot signature 2 without axis labels, with Sanger colors and some transparency so we can see all bars
legoplot3d(contextdata=sigdata$Signature_2,labels=FALSE,scalexy=0.05,sixcolors="sanger",alpha=0.4)
# Plot signature 2 without axis labels, with Sanger colors and some transparency so we can see all bars
legoplot3d(contextdata=sigdata$Signature_8,labels=FALSE,scalexy=0.01,sixcolors="broad",alpha=0.4)
# Input data MUST be in this order
cat(sigdata$Somatic_mutation_type,sep="\n")
# C>A|G>T_AxA
# C>A|G>T_CxA
# C>A|G>T_GxA
# C>A|G>T_TxA
# C>A|G>T_AxC
# C>A|G>T_CxC
# C>A|G>T_GxC
# C>A|G>T_TxC
# C>A|G>T_AxG
# C>A|G>T_CxG
# C>A|G>T_GxG
# C>A|G>T_TxG
# C>A|G>T_AxT
# C>A|G>T_CxT
# C>A|G>T_GxT
# C>A|G>T_TxT
# C>G|G>C_AxA
# C>G|G>C_CxA
# C>G|G>C_GxA
# C>G|G>C_TxA
# C>G|G>C_AxC
# C>G|G>C_CxC
# C>G|G>C_GxC
# C>G|G>C_TxC
# C>G|G>C_AxG
# C>G|G>C_CxG
# C>G|G>C_GxG
# C>G|G>C_TxG
# C>G|G>C_AxT
# C>G|G>C_CxT
# C>G|G>C_GxT
# C>G|G>C_TxT
# C>T|G>A_AxA
# C>T|G>A_CxA
# C>T|G>A_GxA
# C>T|G>A_TxA
# C>T|G>A_AxC
# C>T|G>A_CxC
# C>T|G>A_GxC
# C>T|G>A_TxC
# C>T|G>A_AxG
# C>T|G>A_CxG
# C>T|G>A_GxG
# C>T|G>A_TxG
# C>T|G>A_AxT
# C>T|G>A_CxT
# C>T|G>A_GxT
# C>T|G>A_TxT
# T>A|A>T_AxA
# T>A|A>T_CxA
# T>A|A>T_GxA
# T>A|A>T_TxA
# T>A|A>T_AxC
# T>A|A>T_CxC
# T>A|A>T_GxC
# T>A|A>T_TxC
# T>A|A>T_AxG
# T>A|A>T_CxG
# T>A|A>T_GxG
# T>A|A>T_TxG
# T>A|A>T_AxT
# T>A|A>T_CxT
# T>A|A>T_GxT
# T>A|A>T_TxT
# T>C|A>G_AxA
# T>C|A>G_CxA
# T>C|A>G_GxA
# T>C|A>G_TxA
# T>C|A>G_AxC
# T>C|A>G_CxC
# T>C|A>G_GxC
# T>C|A>G_TxC
# T>C|A>G_AxG
# T>C|A>G_CxG
# T>C|A>G_GxG
# T>C|A>G_TxG
# T>C|A>G_AxT
# T>C|A>G_CxT
# T>C|A>G_GxT
# T>C|A>G_TxT
# T>G|A>C_AxA
# T>G|A>C_CxA
# T>G|A>C_GxA
# T>G|A>C_TxA
# T>G|A>C_AxC
# T>G|A>C_CxC
# T>G|A>C_GxC
# T>G|A>C_TxC
# T>G|A>C_AxG
# T>G|A>C_CxG
# T>G|A>C_GxG
# T>G|A>C_TxG
# T>G|A>C_AxT
# T>G|A>C_CxT
# T>G|A>C_GxT
# T>G|A>C_TxT
## 5.测试完成
sessionInfo()
# R version 3.6.3 (2020-02-29)
# Platform: x86_64-w64-mingw32/x64 (64-bit)
# Running under: Windows 10 x64 (build 18363)
#
# Matrix products: default
#
# locale:
# [1] LC_COLLATE=Chinese (Simplified)_China.936
# [2] LC_CTYPE=Chinese (Simplified)_China.936
# [3] LC_MONETARY=Chinese (Simplified)_China.936
# [4] LC_NUMERIC=C
# [5] LC_TIME=Chinese (Simplified)_China.936
#
# attached base packages:
# [1] stats graphics grDevices utils datasets methods
# [7] base
#
# other attached packages:
# [1] rgl_0.100.54 barplot3d_1.0.1
#
# loaded via a namespace (and not attached):
# [1] Rcpp_1.0.4.6 packrat_0.5.0
# [3] digest_0.6.25 later_1.1.0.1
# [5] mime_0.9 R6_2.4.1
# [7] xtable_1.8-4 jsonlite_1.7.0
# [9] magrittr_1.5 rlang_0.4.6
# [11] miniUI_0.1.1.1 promises_1.1.1
# [13] webshot_0.5.2 tools_3.6.3
# [15] manipulateWidget_0.10.1 htmlwidgets_1.5.1
# [17] crosstalk_1.1.0.1 shiny_1.5.0
# [19] fastmap_1.0.1 httpuv_1.5.4
# [21] xfun_0.15 compiler_3.6.3
# [23] htmltools_0.5.0 knitr_1.29
网友评论