[英]How to add label(annotation) to each plotting dot on R scatterplot3d
The data formate "NB" is as follows.数据格式“NB”如下。
> head(NB)
time speed traffic density
1 06:00 44.04854 304.6616 108.4641
2 06:10 43.73164 332.3510 111.6164
3 06:20 43.35056 359.2273 114.8773
4 06:30 42.91960 382.6465 118.5487
5 06:40 42.42904 400.3864 121.8942
6 06:50 41.91823 415.5429 124.9405
> str(NB)
'data.frame': 85 obs. of 4 variables:
$ time : Factor w/ 144 levels "00:00","00:10",..: 37 38 39 40 41 42 43 44 45 46 ...
$ speed : num 44 43.7 43.4 42.9 42.4 ...
$ traffic: num 305 332 359 383 400 ...
$ density: num 108 112 115 119 122 ...
I have used the below code to make a 3d graph.我使用以下代码制作了 3d 图形。 I want to know how to add the first "time" column to the 3d graph plotted dots and label "time"(06:00, 06:10 .... 20:00)
我想知道如何将第一个“时间”列添加到 3d 图形绘制的点并标记“时间”(06:00、06:10 .... 20:00)
zz <- scatterplot3d(x=NB[,2],y=NB[,3], z=NB[,4],main=naljja,xlab="speed",ylab="traffic",zlab="density",pch=1,color = "blue",grid = TRUE)
Try taking your zz
object (result of scatterplot3d
) and use the xyz.convert
function to transform the coordinates from 3D (x, y, z) to a 2D-projection (x, y).尝试把你的
zz
对象(的结果scatterplot3d
),并使用xyz.convert
函数来从3D(X,Y,Z)变换的坐标为2D投影(X,Y)。 Then use can use text
and add labels to the graph from the time
column (first column).然后使用可以使用
text
并从time
列(第一列)向图形添加标签。 In this case, I used cex
to reduce the text size, and pos
to place label to the right of the points.在这种情况下,我使用
cex
来减小文本大小,并使用pos
将标签放置在点的右侧。
library(scatterplot3d)
zz <- scatterplot3d(x = NB[,2], y = NB[,3], z = NB[,4],
xlab = "speed", ylab = "traffic", zlab = "density",
pch = 1, color = "blue", grid = TRUE)
zz.coords <- zz$xyz.convert(NB[,2], NB[,3], NB[,4])
text(zz.coords$x,
zz.coords$y,
labels = NB[,1],
cex = .5,
pos = 4)
Plot阴谋
Data数据
NB <- structure(list(time = c("06:00", "06:10", "06:20", "06:30", "06:40",
"06:50"), speed = c(44.04854, 43.73164, 43.35056, 42.9196, 42.42904,
41.91823), traffic = c(304.6616, 332.351, 359.2273, 382.6465,
400.3864, 415.5429), density = c(108.4641, 111.6164, 114.8773,
118.5487, 121.8942, 124.9405)), class = "data.frame", row.names = c("1",
"2", "3", "4", "5", "6"))
Reference参考
https://www.r-bloggers.com/2012/01/getting-fancy-with-3-d-scatterplots/ https://www.r-bloggers.com/2012/01/getting-fancy-with-3-d-scatterplots/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.