重现R中的3D图 - 数据作为矩阵,自定义轴和标签

时间:2015-04-01 10:13:47

标签: r plot 3d axis labels

这让我感到非常头疼......但是我得到了一些东西,只是我想要的东西......所以,我怎样才能再现我从R中的设备中获得的图形?

原图:

enter image description here

现在该图表的数据不是100%正确(基于初始读数而不是整个运行期间的最小值) - 因此我获得的图表略有不同,但它的微小差异,这是更正后的数据:< / p>

    P1  P2  P3  P4  P5  P6  P7  P8  P9  P10 P11 P12
5   1.356564    0   0   0   0   0   0.522919    0   0.269146    0.899989    0.996454    0
10  1.677049    0.016866    0   0   0   0.607368    0   0   0   0   0.742411    0
15  2.759722    0   0.602542    0   0.548937    0   0   0   0.148181    0   0.224815    0
20  2.383124    0   0   0   0   0   0.142785    0   0   0   0   0
25  2.194318    0.192807    0   1.278415    0   0.939523    0   0.112651    1.068246    1.16061 1.38776 0.676498
30  2.227332    0.658118    0.504237    0   0.760385    0.137248    0   0.376515    1.517327    1.266435    0.489707    0.974562
35  2.425865    0.571249    0.889235    1.315021    0.511195    0   0   0.414589    1.140811    1.845892    0.098323    0
40  2.56984 1.154292    1.163783    0.796667    0.746664    1.091858    1.122893    1.687882    2.061788    2.724509    2.308096    1.235134
45  2.71372 2.702534    2.704258    2.23746 2.314217    1.892822    1.86525 2.357875    2.554184    1.95893 1.188201    1.71474
50  2.84702 2.649788    2.113081    1.130567    1.357824    0.92954 1.419298    0.995268    0.548421    0.91788 0   0.024919
55  3.283965    0.843004    2.172512    1.763155    0.791001    0.874469    0.548028    1.039265    0.898974    0.227216    1.265553    0.581115
60  4.22087 2.367116    2.663145    2.21502 1.698861    0.571813    1.16839 0.594161    0.585841    0   0   0
65  3.905396    1.513722    2.426271    1.706694    1.34067 1.325783    0.490957    1.981992    0.235005    0.934454    0.940276    0.846207
70  4.649299    2.569352    2.811965    2.19341 2.635729    1.002647    0.915708    1.924824    0.794212    1.294401    1.157521    0.880585
75  4.103029    2.051672    2.758758    2.976522    2.188941    2.07245 2.149921    1.770336    2.685513    1.092814    1.355365    1.008754
80  4.531421    2.321935    3.618583    2.991384    2.537042    1.402546    1.431915    2.2841  1.387641    0.920552    2.044487    0.690089
85  5.199451    3.74389 3.736395    3.487242    2.09652 2.173166    1.911587    1.661859    1.755795    1.590398    1.545263    0.453356
90  5.3198  4.528225    4.328908    4.135772    2.374012    2.560562    2.979826    1.757164    2.13082 2.583608    2.522267    1.471753
95  5.676048    4.557345    5.179662    4.539891    4.028275    2.732066    3.528498    3.509869    2.473462    2.518212    2.026832    1.273347
100 6.53704 5.714319    6.743194    5.071138    3.87076 3.521927    2.769212    3.186856    2.466066    2.562069    1.546379    1.645076
105 6.870514    5.497576    5.636102    5.347473    4.649386    3.425513    3.473505    3.762797    2.721337    2.166123    2.366901    1.826227
110 6.813474    6.881328    5.637504    5.145343    3.972123    4.052656    2.745163    3.562568    4.188948    2.960847    3.056323    2.059925
115 7.719027    7.035191    7.379664    6.839802    5.063594    4.505035    4.020032    4.451296    4.72488 3.22288 3.514651    3.258859
120 8.504394    8.382436    7.485067    6.26145 5.311175    4.512194    4.223568    3.851785    3.984909    2.583755    3.97142 1.825233
125 8.531664    7.561645    8.172427    6.090729    5.211048    5.419967    3.921543    5.067175    4.272155    3.653463    2.593495    2.604687

数据显示在一个外部文件中,该文件由R读入,到目前为止产生了这个:

enter image description here

我正在为Delta_T使用persp和一些杂乱的手动轴标记,但它并不理想...如果我可以使用矩阵中的标题和标签列/行,那么列/ 5是很好的循环次数和位置编号是P1到P12 ...... 理想情况下使用刻度线,能够在后面绘制刻度线也很好... (我确实摆弄了可以给我网格的火山样本,但是我不能轻易地将它绘制成pdf,因为它更具互动性......)

以下是我使用的代码,但我也对替代解决方案持开放态度:

DataIn <- as.matrix(read.table("Processed Banner Data.txt",row.names=1,header=TRUE))

HiReTSOut <- DataIn[,c(12:1)]

z <- HiReTSOut

## colouring method from a presentation on some R plots
nrz <- nrow(HiReTSOut)
ncz <- ncol(HiReTSOut)

jet.colors <- colorRampPalette( c("blue","green","yellow","orange","red"))
nbcol <- 100
color <- jet.colors(nbcol)
zfacet <- z[-1,-1] + z[-1, -ncz] + z[-nrz,-1] + z[-nrz,-ncz]
facetcol <- cut(zfacet, nbcol)


pdf("HiReTS-Banner.pdf",6,5)
par(mar=c(2,2,1,2))

pmat <- 
persp(
HiReTSOut,
col=color[facetcol],
zlim= range(0,200),
xlab="Cycle Number",
ylab="Position Number",
zlab="\n\nDelta T",
theta=-60,
phi=10,
box=TRUE,
#box=FALSE,
#axes=FALSE
axes=TRUE
)


## Long and messy resurce for axis labelling, but gets the job done (to some extent)
## http://entrenchant.blogspot.co.uk/2014/03/custom-tick-labels-in-r-perspective.html

x.axis <- 0:1
min.x <- 0
max.x <- 1
y.axis <- 0:1
min.y <- 0
max.y <- 1
z.axis <- seq(0, 200, by=20)
min.z <- 0
max.z <- 20

tick.start <- trans3d(max.x, min.y, z.axis, pmat)
tick.end <- trans3d(max.x, (min.y - 0.025), z.axis, pmat)
segments(tick.start$x, tick.start$y, tick.end$x, tick.end$y)

tick.start <- trans3d(min.x, max.y, z.axis, pmat)
tick.end <- trans3d(min.x - 0.025 , max.y, z.axis, pmat)
segments(tick.start$x, tick.start$y, tick.end$x, tick.end$y)


labels <- as.character(z.axis)
label.pos <- trans3d(max.x, (min.y - 0.05), z.axis, pmat)
text(label.pos$x, label.pos$y, labels=labels, adj=c(0, NA), cex=0.75)

labels <- as.character(z.axis)
label.pos <- trans3d(min.x, (max.y + 0.1), z.axis, pmat)
text(label.pos$x, label.pos$y, labels=labels, adj=c(1, NA), cex=0.75)


dev.off()

我可以使用与绘制刻度相同的方法绘制线条,但是它会覆盖在表面上并且看起来有点难看......

考虑到R上有多少个绘图问题,也许有可能将其发展成某种可以帮助他人的一般Wiki风格条目?

0 个答案:

没有答案