I want to add a subtitle to multiple histograms that I created by rotating with for.

Asked 1 years ago, Updated 1 years ago, 287 views

#Initialize variable to store subtitle
title<-"

# Read the CSV file containing the subtitle and process it line by line
title_file<-read.csv("ID_Name.txt", header=FALSE)
for(i in 1:nrow(subtitle_file)){
  # store a subtitle in a variable
  subtitle<-paste(subtitle, subtitle_file[i, 2], sep="")
}

path<-'./path/'
files<-list.files(path)
n<-length (files)

for (i in 1:n) {
  file<-paste('./path/', files[i], sep="")
  print(file)
  
  data<-read.csv(file)
  f_out<-paste('./path/', files[i], '.png', sep="")
  print(f_out)
  png(f_out)# Open Drawing Device
  hist(data[,2],main="",xlab="Ah",ylab="Good",sub=subtitle)
  dev.off()#Close drawing device
}

In the above script, all subtitle_file[i, 2] are added together.I would like to create a script in which one of the substitute_file[i, 2] is added sequentially whenever a histogram is created.
The number of files used to create the histogram matches the number of lines with ID_Name.txt.

r

2023-02-27 14:39

1 Answers

Vector should be the best.

df<-read.csv("ID_Name.txt", header=FALSE)
title<-df[,2]
          :

for (i in 1:n) {
          :

  hist(data[,2],main="",xlab="Ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
          :

}


2023-02-27 14:48

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.