printer_data<-read.csv("D:/Bài tập R/data.csv")
head(printer_data,3)
##   layer_height wall_thickness infill_density infill_pattern nozzle_temperature
## 1         0.02              8             90           grid                220
## 2         0.02              7             90      honeycomb                225
## 3         0.02              1             80           grid                230
##   bed_temperature print_speed material fan_speed roughness tension_strenght
## 1              60          40      abs         0        25               18
## 2              65          40      abs        25        32               16
## 3              70          40      abs        50        40                8
##   elongation
## 1        1.2
## 2        1.4
## 3        0.8
new_DF <-printer_data[,c("layer_height","wall_thickness","infill_density", "infill_pattern","nozzle_temperature","bed_temperature","print_speed", "material","fan_speed","tension_strenght")]
head(new_DF,3)
##   layer_height wall_thickness infill_density infill_pattern nozzle_temperature
## 1         0.02              8             90           grid                220
## 2         0.02              7             90      honeycomb                225
## 3         0.02              1             80           grid                230
##   bed_temperature print_speed material fan_speed tension_strenght
## 1              60          40      abs         0               18
## 2              65          40      abs        25               16
## 3              70          40      abs        50                8
library(questionr)
freq.na(new_DF)
##                    missing %
## layer_height             0 0
## wall_thickness           0 0
## infill_density           0 0
## infill_pattern           0 0
## nozzle_temperature       0 0
## bed_temperature          0 0
## print_speed              0 0
## material                 0 0
## fan_speed                0 0
## tension_strenght         0 0
new_function <- function(x){
  c(n = length(x),
  xtb = mean(x),
  sd = sd(x),
  Q1 = quantile(x,probs = 0.25),
  Q2 = median(x),
  Q3 = quantile(x,probs = 0.75),
  min = min(x),
  max = max(x))}
continous_data <- new_DF[,c("layer_height","wall_thickness","infill_density",
                            "nozzle_temperature","bed_temperature","print_speed"
                          ,"fan_speed","tension_strenght")]
apply(continous_data, 2, new_function)
##        layer_height wall_thickness infill_density nozzle_temperature
## n       50.00000000      50.000000       50.00000           50.00000
## xtb      0.10600000       5.220000       53.40000          221.50000
## sd       0.06439673       2.922747       25.36348           14.82035
## Q1.25%   0.06000000       3.000000       40.00000          210.00000
## Q2       0.10000000       5.000000       50.00000          220.00000
## Q3.75%   0.15000000       7.000000       80.00000          230.00000
## min      0.02000000       1.000000       10.00000          200.00000
## max      0.20000000      10.000000       90.00000          250.00000
##        bed_temperature print_speed fan_speed tension_strenght
## n            50.000000     50.0000  50.00000        50.000000
## xtb          70.000000     64.0000  50.00000        20.080000
## sd            7.142857     29.6923  35.71429         8.925634
## Q1.25%       65.000000     40.0000  25.00000        12.000000
## Q2           70.000000     60.0000  50.00000        19.000000
## Q3.75%       75.000000     60.0000  75.00000        27.000000
## min          60.000000     40.0000   0.00000         4.000000
## max          80.000000    120.0000 100.00000        37.000000
table(new_DF$infill_pattern)
## 
##      grid honeycomb 
##        25        25
table(new_DF$material)
## 
## abs pla 
##  25  25
hist(new_DF$ tension_strenght ,
     main =" Histogram of tension _strenght ",
     xlab =" tension _ strenght ",
     ylab = "Tan so",
     col =" pink ",
     border = "black",
     labels = TRUE,
     ylim = c(0, 15))

boxplot(tension_strenght~infill_pattern,
        data=new_DF,
        col=c("orange"," green "),
        xlab = "Infill Pattern",
        ylab = "Tension_Strenght",
        main =" tension_strenght and infill_pattern ")

boxplot(tension_strenght~material,
        data=new_DF,
        col=c("orange"," green "),
        xlab = "material",
        ylab = "Tension_Strenght",
        main =" tension_strenght and material ")

variables <- c("layer_height","wall_thickness",
          "infill_density","fan_speed","nozzle_temperature",
           "print_speed","bed_temperature")
par(mfrow = c(2,4))
for(v in variables){
  plot(new_DF[[v]], new_DF$tension_strenght, 
       xlab = v, 
       ylab = "tension_strenght", 
       main = paste(v, "& tension_strenght"), 
       pch = 1)
}

par(mfrow = c(1,1))
library(corrplot)
## corrplot 0.95 loaded
cor(continous_data)
##                    layer_height wall_thickness infill_density
## layer_height         1.00000000    -0.19257144     0.00349856
## wall_thickness      -0.19257144     1.00000000     0.10257623
## infill_density       0.00349856     0.10257623     1.00000000
## nozzle_temperature   0.00000000    -0.11849286     0.23861372
## bed_temperature      0.00000000    -0.02932662     0.00000000
## print_speed         -0.05550085    -0.41953069    -0.09430408
## fan_speed            0.00000000    -0.02932662     0.00000000
## tension_strenght     0.33822961     0.39984948     0.35846444
##                    nozzle_temperature bed_temperature print_speed   fan_speed
## layer_height                0.0000000      0.00000000 -0.05550085  0.00000000
## wall_thickness             -0.1184929     -0.02932662 -0.41953069 -0.02932662
## infill_density              0.2386137      0.00000000 -0.09430408  0.00000000
## nozzle_temperature          1.0000000      0.60245337  0.00000000  0.60245337
## bed_temperature             0.6024534      1.00000000  0.00000000  1.00000000
## print_speed                 0.0000000      0.00000000  1.00000000  0.00000000
## fan_speed                   0.6024534      1.00000000  0.00000000  1.00000000
## tension_strenght           -0.4059076     -0.25288320 -0.26459046 -0.25288320
##                    tension_strenght
## layer_height              0.3382296
## wall_thickness            0.3998495
## infill_density            0.3584644
## nozzle_temperature       -0.4059076
## bed_temperature          -0.2528832
## print_speed              -0.2645905
## fan_speed                -0.2528832
## tension_strenght          1.0000000
bang_ma_tran <- cor(continous_data)
corrplot(bang_ma_tran, 
         method = "number", 
         tl.cex = 0.8, 
         number.cex = 0.7)