使用R包barplot3d绘制3D条形图-2020-07-04Sat

## 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

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 216,287评论 6 498
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,346评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 162,277评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,132评论 1 292
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,147评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,106评论 1 295
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,019评论 3 417
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,862评论 0 274
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,301评论 1 310
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,521评论 2 332
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,682评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,405评论 5 343
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,996评论 3 325
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,651评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,803评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,674评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,563评论 2 352