options(repos = "https://cran.rstudio.com/")
# Set the CRAN mirror
options(repos = "https://cran.rstudio.com/")

# Install the 'tidyverse' package
install.packages("tidyverse")
## Installing package into 'C:/Users/meebo/AppData/Local/R/win-library/4.3'
## (as 'lib' is unspecified)
## package 'tidyverse' successfully unpacked and MD5 sums checked
## 
## The downloaded binary packages are in
##  C:\Users\meebo\AppData\Local\Temp\RtmpyMIRfv\downloaded_packages
# First function to transform dataframe
readInData <- function(path) {
  # Read in the file
  lines <- readLines(path)
  
  # Extract the data from each line
  x_vals <- gsub("\\[x = (.*?), y = (.*?)\\].*", "\\1", lines)
  y_vals <- gsub("\\[x = (.*?), y = (.*?)\\].*", "\\2", lines)
  red_vals <- gsub(".*\\[red = (.*?),.*", "\\1", lines)
  green_vals <- gsub(".*green = (.*?),.*", "\\1", lines)
  blue_vals <- gsub(".*blue = (.*?)]", "\\1", lines)
  
  # Convert the extracted data to a data frame
 d0 <- data.frame(x = as.numeric(x_vals), y = as.numeric(y_vals),
                      red = as.numeric(red_vals), green = as.numeric(green_vals), 
                      blue = as.numeric(blue_vals))
  
  return(d0)
}
d0 <- readInData(path = "D:/STUDY/STUDY/R/Color.csv")
## Warning in readLines(path): incomplete final line found on
## 'D:/STUDY/STUDY/R/Color.csv'
head(d0)
##           x         y      red green     blue
## 1 -0.287388 -0.312438 0.512212     0 0.424932
## 2  2.243610 -1.290370 0.690404     0 0.349043
## 3  0.781732 -0.220037 0.587483     0 0.432103
## 4 -3.359720  2.964130 0.295908     0 0.679201
## 5  1.753710 -1.716940 0.655913     0 0.315940
## 6  1.980620 -1.460900 0.671889     0 0.335810
# Second function to plot the graph
makePlot <- function(d0, pch = 1, col = rgb(d0$red, d0$green, d0$blue),
                     xlab = "", ylab = "", main = "", cex = 1) {
  plot(d0$x, d0$y, pch = pch, col = col, xlab = xlab, ylab = ylab, main = main, cex = cex)
}

makePlot(d0, pch = 20, xlab = "x", ylab = "y", cex = 0.8)