getwd()
## [1] "C:/Users/skirmantas/OneDrive/Desktop"
setwd("C:/Users/skirmantas/OneDrive/Desktop")
duom <- read.csv2("C:/Users/skirmantas/OneDrive/Desktop/Duomenys/DPP.csv", header = TRUE, sep = ";", dec = ".")
library(ggplot2)
library(plot3D)
library(rgl)

library(RColorBrewer)
library(reshape2)
library(scales)
library(dplyr)
## Warning: paketas 'dplyr' buvo sukurtas pagal R versijà 4.1.3
## 
## Pridedamas paketas: 'dplyr'
## Šie objektai yra užmaskuoti nuo 'package:stats':
## 
##     filter, lag
## Šie objektai yra užmaskuoti nuo 'package:base':
## 
##     intersect, setdiff, setequal, union
library(plotly)
## 
## Pridedamas paketas: 'plotly'
## Šis objektas yra užmaskuotas nuo 'package:ggplot2':
## 
##     last_plot
## Šis objektas yra užmaskuotas nuo 'package:stats':
## 
##     filter
## Šis objektas yra užmaskuotas nuo 'package:graphics':
## 
##     layout
library(tidyr)
## 
## Pridedamas paketas: 'tidyr'
## Šis objektas yra užmaskuotas nuo 'package:reshape2':
## 
##     smiths
library(ggridges)
## Warning: paketas 'ggridges' buvo sukurtas pagal R versijà 4.1.3
ilgis <- 20
x <- duom$Depth[1:20]
y <- duom$Table[1:20]
j <- duom$X.length.[1:20]

Euklidinis atstumas

df <- data.frame(x, y, j)
data <- as.matrix(df)

dist_euc <- as.matrix(dist(df, method = "euclidean"))
dist_eu <- as.data.frame(dist_euc)
temp <- NULL
for(i in 1:ilgis)
{
  temp <- rbind(temp,cbind(seq(1, ilgis, 1) ,rep(i, ilgis),dist_eu[,i]))
}
temp <- as.data.frame(temp)
temp$V1 <- as.character(temp$V1)
temp$V2 <- as.character(temp$V2)
temp$V1 <- factor(temp$V1, levels = 1:ilgis)
temp$V2 <- factor(temp$V2, levels = 1:ilgis)
names(temp)[3] <- "Distance"



ggplot(temp, aes(V1, V2, fill= Distance)) + 
  labs(title = "Distance between elements",
       x = "Object Number", y = "Object Number") +
  geom_tile() +
  scale_fill_gradient("Distance between\nelements", low="pink", high="purple")

Manheteno atstumas

dist_euc <- as.matrix(dist(df, method = "manhattan"))
dist_eu <- as.data.frame(dist_euc)
temp <- NULL
for(i in 1:ilgis)
{
  temp <- rbind(temp,cbind(seq(1, ilgis, 1) ,rep(i, ilgis),dist_eu[,i]))
}
temp <- as.data.frame(temp)
temp$V1 <- as.character(temp$V1)
temp$V2 <- as.character(temp$V2)
temp$V1 <- factor(temp$V1, levels = 1:ilgis)
temp$V2 <- factor(temp$V2, levels = 1:ilgis)
names(temp)[3] <- "Distance"

#Manheteno atstumas

ggplot(temp, aes(V1, V2, fill= Distance)) + 
  labs(title = "Distance between elements",
       x = "Object Number", y = "Object Number") +
  geom_tile() +
  scale_fill_gradient("Distance between elements", low="green", high="yellow")

Čebyševo atstumas

dist_euc <- as.matrix(dist(df, method = "maximum"))
dist_eu <- as.data.frame(dist_euc)
temp <- NULL
for(i in 1:ilgis)
{
  temp <- rbind(temp,cbind(seq(1, ilgis, 1) ,rep(i, ilgis),dist_eu[,i]))
}
temp <- as.data.frame(temp)
temp$V1 <- as.character(temp$V1)
temp$V2 <- as.character(temp$V2)
temp$V1 <- factor(temp$V1, levels = 1:ilgis)
temp$V2 <- factor(temp$V2, levels = 1:ilgis)
names(temp)[3] <- "Distance"

Čebyševo atstumas

ggplot(temp, aes(V1, V2, fill= Distance)) + 
  labs(title = "Distance between elements",
       x = "Object Number", y = "Object Number") +
  geom_tile() +
  scale_fill_gradient("Distance between\nelements", low="darkorchid", high="yellow")