在这种情况下,我实际上已经陷入了创建矩阵的困境。让我们先从数据开始:
Length Diameter Defect Start Defect End Defect Location Defect Angle
1 9850 100 975 987 986 0
2 9850 100 1937 1949 709 0
3 9850 100 4775 4787 604 0
4 9850 100 5775 5787 15 0
5 9850 100 6062 6087 44 -3
6 9850 100 6325 6337 385 0
7 9850 100 6650 6675 588 0
这是输入:
structure(list(Length = c(9850, 9850, 9850, 9850, 9850, 9850,
9850), Diameter = c(100, 100, 100, 100, 100, 100, 100), `Defect Start` = c(975,
1937, 4775, 5775, 6062, 6325, 6650), `Defect End` = c(987, 1949,
4787, 5787, 6087, 6337, 6675), `Defect Location` = c(986, 709,
604, 15, 44, 385, 588), `Defect Angle` = c(0, 0, 0, 0, -3, 0,
0)), class = "data.frame", row.names = c(NA, -7L))
和数据的图形解释如下(快速油漆解决方案)
目标
目标是使用例如等高线图(x轴长度,y轴直径等)创建2d或3d图,以显示缺陷的位置(缺陷始终是简单的线条具有开始 缺陷开始和结束 缺陷结束 长度的位置和卷中宽度的缺陷位置)。
我一直在准备矩阵,但实际上我什至不知道是否有可能在R中完成它,但我想这将是一个很棒且有趣的方法!
如果您有任何提示,我将不胜感激!
答案 0 :(得分:1)
这是个主意。
将每个管道绘制为2d矩形,在上面显示缺陷。
要做的事情:
-弄清楚Defect Location
的含义
-需要角度吗?
library(tidyverse)
df <- mydata %>%
#give the pipe an id
mutate( id = 1 ) %>%
group_by( id ) %>%
#give each defect (by pipe) an id
mutate( defect_id = row_number() ) %>%
#not sure what to do woith defect location....
#to get it inside the pipe, i divide by 10... needs looking into!!
mutate( `Defect Location` = `Defect Location` / 10 ) %>%
gather("defect", "x", -Length, -Diameter, -`Defect Angle`, -id, -defect_id, -`Defect Location`)
ggplot( data = df ) +
#draw pipe as a 2D rectangle, height = pi * Diameter
geom_rect( aes( xmin = 0, xmax = Length, ymin = 0, ymax = pi * Diameter ), alpha = 0.1 ) +
#draw start-endpoint and lines with defects
geom_point( aes( x = x, y = `Defect Location`, group = as.character(defect_id) ), color = "red", size = 2 ) +
geom_line( aes( x = x, y = `Defect Location`, group = as.character(defect_id), colour = as.character(defect_id) ), color = "red", size = 2 ) +
#draw each pipe
facet_wrap( ~id, ncol = 1 )