Hi everyone,
I am new to R programming, and I am having difficulties modifying an R
script to introduce the "for" loop in the code.
While searching I found that this issue has already been raised, but I did
not know what to do to fix mine !
*The code that works (without for command):*
CPM <- read.table("FicConfig/CPM.txt" , header = TRUE, sep = "\t" , dec =
",", skip = 0)
# The CPM.txt file containe 1 line
......................................................................
......................................................................
options(viewer = NULL)
plot_ly() %>%
htmlwidgets::onRender(
"function(el, x) {
var gd = document.getElementById(el.id);
Plotly.downloadImage(gd, {format: 'png', width: 1000, height: 700,
filename: 'AnomalieRR_EcartTmoy'});
}"
)%>%
add_trace(x =TAnn[ ,3], y = TAnn[ ,5], name = "Normale mensuelle de
Tmax(en ?C)",type = 'scatter', mode = 'markers', marker = list(size = T,
symbol = 'circle', color = ~TAnn[ ,5], line = list(width= 2, color = cl)))
%>%
add_annotations(text = TAnn[ ,1], x= TAnn[ ,3], y = TAnn[ ,5], font =
list(color = "white", size = 14), showarrow = FALSE)%>%
layout(title = paste("Combinaison anomalie relative annuelle des
pr?cipitations et ?cart annuel ? la normale de la temp?rature moyenne ?
",CPM[1,1],sep =""),
xaxis = list(title = "Anomalie relative des pr?cipitations
annuelles(en %)", tickangle = 20 ,titlefont = list(color= "blue", size= 14
, family = 'Arial'), tickfont = list(color = "blue", size = 14)),
yaxis = list(title = "Ecart ? la normale de la temp?rature moyenne
annuelle(en?C)", titlefont = list(color= "red", size= 14 , family =
'Arial'),
tickfont = list(color = "red", size = 14) , showline = TRUE, linecolor =
"red", linewidth = 2),
legend = list(x = 0.1, y = -0.3, font=list(size = 14,color=
"black")),margin = list(
t = 70,
r = 70,
b = 70,
l = 70
))
*The code that does not work (with for command):*
CPM <- read.table("FicConfig/CPM.txt" , header = TRUE, sep = "\t" , dec =
",", skip = 0)
# The CPM.txt file containe several lines
*for (i in 1: (nrow(CPM))) {*
options(viewer = NULL)
plot_ly() %>%
htmlwidgets::onRender(
"function(el, x) {
var gd = document.getElementById(el.id);
Plotly.downloadImage(gd, {format: 'png', width: 1000, height: 700,
filename: 'AnomalieRR_EcartTmoy'});
}"
)%>%
add_trace(x =TAnn[ ,3], y = TAnn[ ,5], name = "Normale mensuelle de
Tmax(en ?C)",type = 'scatter', mode = 'markers', marker = list(size = T,
symbol = 'circle', color = ~TAnn[ ,5], line = list(width= 2, color = cl)))
%>%
add_annotations(text = TAnn[ ,1], x= TAnn[ ,3], y = TAnn[ ,5], font =
list(color = "white", size = 14), showarrow = FALSE)%>%
layout(title = paste("Combinaison anomalie relative annuelle des
pr?cipitations et ?cart annuel ? la normale de la temp?rature moyenne ?
",CPM[i,1],sep =""),
xaxis = list(title = "Anomalie relative des pr?cipitations
annuelles(en %)", tickangle = 20 ,titlefont = list(color= "blue", size= 14
, family = 'Arial'), tickfont = list(color = "blue", size = 14)),
yaxis = list(title = "Ecart ? la normale de la temp?rature moyenne
annuelle(en?C)", titlefont = list(color= "red", size= 14 , family =
'Arial'),
tickfont = list(color = "red", size = 14) , showline = TRUE, linecolor =
"red", linewidth = 2),
legend = list(x = 0.1, y = -0.3, font=list(size = 14,color=
"black")),margin = list(
t = 70,
r = 70,
b = 70,
l = 70
))
*file.copy("C:/Users/pc/Downloads/Evolution Tmoy.png",
paste("C:/MONOGRAPHIE/Resultats/Evolution Tmoy_",CPM[i,1],".png",sep="")*
*}*
Thank you very much in advance for any help.
"for" loop does not work with my plot_ly command
7 messages · Mika Hamari, Jim Lemon, Rachida El Ouaraini +1 more
Hi!
I am also learning, but I want try to help. I often use for-loop in R. I think that it could be due to dimensions of CPM, not the structure of the loop.
What kind of error message do you get? Is it: ?incorrect number of dimensions?? What happens if you substitute in the end instead of CPM[i,1] this:
file.copy("C:/Users/pc/Downloads/Evolution Tmoy.png",
paste("C:/MONOGRAPHIE/Resultats/Evolution Tmoy_",CPM[i],".png",sep="")
L?hett?j?: Rachida El Ouaraini<mailto:elouaraini at gmail.com>
L?hetetty: maanantai 29. maaliskuuta 2021 18.15
Vastaanottaja: r-help at r-project.org<mailto:r-help at r-project.org>
Aihe: [R] "for" loop does not work with my plot_ly command
Hi everyone,
I am new to R programming, and I am having difficulties modifying an R
script to introduce the "for" loop in the code.
While searching I found that this issue has already been raised, but I did
not know what to do to fix mine !
*The code that works (without for command):*
CPM <- read.table("FicConfig/CPM.txt" , header = TRUE, sep = "\t" , dec =
",", skip = 0)
# The CPM.txt file containe 1 line
......................................................................
......................................................................
options(viewer = NULL)
plot_ly() %>%
htmlwidgets::onRender(
"function(el, x) {
var gd = document.getElementById(el.id);
Plotly.downloadImage(gd, {format: 'png', width: 1000, height: 700,
filename: 'AnomalieRR_EcartTmoy'});
}"
)%>%
add_trace(x =TAnn[ ,3], y = TAnn[ ,5], name = "Normale mensuelle de
Tmax(en ?C)",type = 'scatter', mode = 'markers', marker = list(size = T,
symbol = 'circle', color = ~TAnn[ ,5], line = list(width= 2, color = cl)))
%>%
add_annotations(text = TAnn[ ,1], x= TAnn[ ,3], y = TAnn[ ,5], font =
list(color = "white", size = 14), showarrow = FALSE)%>%
layout(title = paste("Combinaison anomalie relative annuelle des
pr?cipitations et ?cart annuel ? la normale de la temp?rature moyenne ?
",CPM[1,1],sep =""),
xaxis = list(title = "Anomalie relative des pr?cipitations
annuelles(en %)", tickangle = 20 ,titlefont = list(color= "blue", size= 14
, family = 'Arial'), tickfont = list(color = "blue", size = 14)),
yaxis = list(title = "Ecart ? la normale de la temp?rature moyenne
annuelle(en?C)", titlefont = list(color= "red", size= 14 , family =
'Arial'),
tickfont = list(color = "red", size = 14) , showline = TRUE, linecolor =
"red", linewidth = 2),
legend = list(x = 0.1, y = -0.3, font=list(size = 14,color=
"black")),margin = list(
t = 70,
r = 70,
b = 70,
l = 70
))
*The code that does not work (with for command):*
CPM <- read.table("FicConfig/CPM.txt" , header = TRUE, sep = "\t" , dec =
",", skip = 0)
# The CPM.txt file containe several lines
*for (i in 1: (nrow(CPM))) {*
options(viewer = NULL)
plot_ly() %>%
htmlwidgets::onRender(
"function(el, x) {
var gd = document.getElementById(el.id);
Plotly.downloadImage(gd, {format: 'png', width: 1000, height: 700,
filename: 'AnomalieRR_EcartTmoy'});
}"
)%>%
add_trace(x =TAnn[ ,3], y = TAnn[ ,5], name = "Normale mensuelle de
Tmax(en ?C)",type = 'scatter', mode = 'markers', marker = list(size = T,
symbol = 'circle', color = ~TAnn[ ,5], line = list(width= 2, color = cl)))
%>%
add_annotations(text = TAnn[ ,1], x= TAnn[ ,3], y = TAnn[ ,5], font =
list(color = "white", size = 14), showarrow = FALSE)%>%
layout(title = paste("Combinaison anomalie relative annuelle des
pr?cipitations et ?cart annuel ? la normale de la temp?rature moyenne ?
",CPM[i,1],sep =""),
xaxis = list(title = "Anomalie relative des pr?cipitations
annuelles(en %)", tickangle = 20 ,titlefont = list(color= "blue", size= 14
, family = 'Arial'), tickfont = list(color = "blue", size = 14)),
yaxis = list(title = "Ecart ? la normale de la temp?rature moyenne
annuelle(en?C)", titlefont = list(color= "red", size= 14 , family =
'Arial'),
tickfont = list(color = "red", size = 14) , showline = TRUE, linecolor =
"red", linewidth = 2),
legend = list(x = 0.1, y = -0.3, font=list(size = 14,color=
"black")),margin = list(
t = 70,
r = 70,
b = 70,
l = 70
))
*file.copy("C:/Users/pc/Downloads/Evolution Tmoy.png",
paste("C:/MONOGRAPHIE/Resultats/Evolution Tmoy_",CPM[i,1],".png",sep="")*
*}*
Thank you very much in advance for any help.
______________________________________________
R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=04%7C01%7C%7C63572d98fe1f4af1938c08d8f2c57a0e%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637526277319446692%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=wwtfLAGJ3zjOzN%2FDxopVDEVnLC5QSF6H1ER6nHMEaLI%3D&reserved=0
PLEASE do read the posting guide https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.html&data=04%7C01%7C%7C63572d98fe1f4af1938c08d8f2c57a0e%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637526277319446692%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=nqKgiTsjQz%2FjF5gDRc1UMQiSxRdZCurArqyGz5pnNtg%3D&reserved=0
and provide commented, minimal, self-contained, reproducible code.
Hi Rachida,
My guess is that you create a vector of filenames:
filenames<-list.files(path="FicConfig",pattern="*.txt")
then use the filenames in the loop:
for(filename in filenames) {
nextfile<- read.table(filename, header = TRUE, sep = "\t" , dec =
",", skip = 0)
# do whatever you want with the resulting data frame here
# or perhaps save it into a list for processing later
}
Jim
On Tue, Mar 30, 2021 at 2:15 AM Rachida El Ouaraini
<elouaraini at gmail.com> wrote:
Hi everyone,
I am new to R programming, and I am having difficulties modifying an R
script to introduce the "for" loop in the code.
While searching I found that this issue has already been raised, but I did
not know what to do to fix mine !
*The code that works (without for command):*
CPM <- read.table("FicConfig/CPM.txt" , header = TRUE, sep = "\t" , dec =
",", skip = 0)
# The CPM.txt file containe 1 line
......................................................................
......................................................................
options(viewer = NULL)
plot_ly() %>%
htmlwidgets::onRender(
"function(el, x) {
var gd = document.getElementById(el.id);
Plotly.downloadImage(gd, {format: 'png', width: 1000, height: 700,
filename: 'AnomalieRR_EcartTmoy'});
}"
)%>%
add_trace(x =TAnn[ ,3], y = TAnn[ ,5], name = "Normale mensuelle de
Tmax(en ?C)",type = 'scatter', mode = 'markers', marker = list(size = T,
symbol = 'circle', color = ~TAnn[ ,5], line = list(width= 2, color = cl)))
%>%
add_annotations(text = TAnn[ ,1], x= TAnn[ ,3], y = TAnn[ ,5], font =
list(color = "white", size = 14), showarrow = FALSE)%>%
layout(title = paste("Combinaison anomalie relative annuelle des
pr?cipitations et ?cart annuel ? la normale de la temp?rature moyenne ?
",CPM[1,1],sep =""),
xaxis = list(title = "Anomalie relative des pr?cipitations
annuelles(en %)", tickangle = 20 ,titlefont = list(color= "blue", size= 14
, family = 'Arial'), tickfont = list(color = "blue", size = 14)),
yaxis = list(title = "Ecart ? la normale de la temp?rature moyenne
annuelle(en?C)", titlefont = list(color= "red", size= 14 , family =
'Arial'),
tickfont = list(color = "red", size = 14) , showline = TRUE, linecolor =
"red", linewidth = 2),
legend = list(x = 0.1, y = -0.3, font=list(size = 14,color=
"black")),margin = list(
t = 70,
r = 70,
b = 70,
l = 70
))
*The code that does not work (with for command):*
CPM <- read.table("FicConfig/CPM.txt" , header = TRUE, sep = "\t" , dec =
",", skip = 0)
# The CPM.txt file containe several lines
*for (i in 1: (nrow(CPM))) {*
options(viewer = NULL)
plot_ly() %>%
htmlwidgets::onRender(
"function(el, x) {
var gd = document.getElementById(el.id);
Plotly.downloadImage(gd, {format: 'png', width: 1000, height: 700,
filename: 'AnomalieRR_EcartTmoy'});
}"
)%>%
add_trace(x =TAnn[ ,3], y = TAnn[ ,5], name = "Normale mensuelle de
Tmax(en ?C)",type = 'scatter', mode = 'markers', marker = list(size = T,
symbol = 'circle', color = ~TAnn[ ,5], line = list(width= 2, color = cl)))
%>%
add_annotations(text = TAnn[ ,1], x= TAnn[ ,3], y = TAnn[ ,5], font =
list(color = "white", size = 14), showarrow = FALSE)%>%
layout(title = paste("Combinaison anomalie relative annuelle des
pr?cipitations et ?cart annuel ? la normale de la temp?rature moyenne ?
",CPM[i,1],sep =""),
xaxis = list(title = "Anomalie relative des pr?cipitations
annuelles(en %)", tickangle = 20 ,titlefont = list(color= "blue", size= 14
, family = 'Arial'), tickfont = list(color = "blue", size = 14)),
yaxis = list(title = "Ecart ? la normale de la temp?rature moyenne
annuelle(en?C)", titlefont = list(color= "red", size= 14 , family =
'Arial'),
tickfont = list(color = "red", size = 14) , showline = TRUE, linecolor =
"red", linewidth = 2),
legend = list(x = 0.1, y = -0.3, font=list(size = 14,color=
"black")),margin = list(
t = 70,
r = 70,
b = 70,
l = 70
))
*file.copy("C:/Users/pc/Downloads/Evolution Tmoy.png",
paste("C:/MONOGRAPHIE/Resultats/Evolution Tmoy_",CPM[i,1],".png",sep="")*
*}*
Thank you very much in advance for any help.
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Hi Mika, and thank you very much for your answer. When I add the "for" loop to the code that produces before the graph I want, it does nothing : NO graph and NO error message. It seems to me that the command plot_ly and the for loop DO NOT coexist. Rachida On Mon, Mar 29, 2021 at 7:44 PM Mika Hamari <mika.hamari73 at outlook.com> wrote:
Hi!
I am also learning, but I want try to help. I often use for-loop in R. I
think that it could be due to dimensions of CPM, not the structure of the
loop.
What kind of error message do you get? Is it: ?incorrect number of
dimensions?? What happens if you substitute in the end instead of CPM[i,1]
this:
file.copy("C:/Users/pc/Downloads/Evolution Tmoy.png",
paste("C:/MONOGRAPHIE/Resultats/Evolution Tmoy_",CPM[i],".png",sep="")
*L?hett?j?: *Rachida El Ouaraini <elouaraini at gmail.com>
*L?hetetty: *maanantai 29. maaliskuuta 2021 18.15
*Vastaanottaja: *r-help at r-project.org
*Aihe: *[R] "for" loop does not work with my plot_ly command
Hi everyone,
I am new to R programming, and I am having difficulties modifying an R
script to introduce the "for" loop in the code.
While searching I found that this issue has already been raised, but I did
not know what to do to fix mine !
*The code that works (without for command):*
CPM <- read.table("FicConfig/CPM.txt" , header = TRUE, sep = "\t" , dec =
",", skip = 0)
# The CPM.txt file containe 1 line
......................................................................
......................................................................
options(viewer = NULL)
plot_ly() %>%
htmlwidgets::onRender(
"function(el, x) {
var gd = document.getElementById(el.id);
Plotly.downloadImage(gd, {format: 'png', width: 1000, height: 700,
filename: 'AnomalieRR_EcartTmoy'});
}"
)%>%
add_trace(x =TAnn[ ,3], y = TAnn[ ,5], name = "Normale mensuelle de
Tmax(en ?C)",type = 'scatter', mode = 'markers', marker = list(size = T,
symbol = 'circle', color = ~TAnn[ ,5], line = list(width= 2, color = cl)))
%>%
add_annotations(text = TAnn[ ,1], x= TAnn[ ,3], y = TAnn[ ,5], font =
list(color = "white", size = 14), showarrow = FALSE)%>%
layout(title = paste("Combinaison anomalie relative annuelle des
pr?cipitations et ?cart annuel ? la normale de la temp?rature moyenne ?
",CPM[1,1],sep =""),
xaxis = list(title = "Anomalie relative des pr?cipitations
annuelles(en %)", tickangle = 20 ,titlefont = list(color= "blue", size= 14
, family = 'Arial'), tickfont = list(color = "blue", size = 14)),
yaxis = list(title = "Ecart ? la normale de la temp?rature moyenne
annuelle(en?C)", titlefont = list(color= "red", size= 14 , family =
'Arial'),
tickfont = list(color = "red", size = 14) , showline = TRUE, linecolor =
"red", linewidth = 2),
legend = list(x = 0.1, y = -0.3, font=list(size = 14,color=
"black")),margin = list(
t = 70,
r = 70,
b = 70,
l = 70
))
*The code that does not work (with for command):*
CPM <- read.table("FicConfig/CPM.txt" , header = TRUE, sep = "\t" , dec =
",", skip = 0)
# The CPM.txt file containe several lines
*for (i in 1: (nrow(CPM))) {*
options(viewer = NULL)
plot_ly() %>%
htmlwidgets::onRender(
"function(el, x) {
var gd = document.getElementById(el.id);
Plotly.downloadImage(gd, {format: 'png', width: 1000, height: 700,
filename: 'AnomalieRR_EcartTmoy'});
}"
)%>%
add_trace(x =TAnn[ ,3], y = TAnn[ ,5], name = "Normale mensuelle de
Tmax(en ?C)",type = 'scatter', mode = 'markers', marker = list(size = T,
symbol = 'circle', color = ~TAnn[ ,5], line = list(width= 2, color = cl)))
%>%
add_annotations(text = TAnn[ ,1], x= TAnn[ ,3], y = TAnn[ ,5], font =
list(color = "white", size = 14), showarrow = FALSE)%>%
layout(title = paste("Combinaison anomalie relative annuelle des
pr?cipitations et ?cart annuel ? la normale de la temp?rature moyenne ?
",CPM[i,1],sep =""),
xaxis = list(title = "Anomalie relative des pr?cipitations
annuelles(en %)", tickangle = 20 ,titlefont = list(color= "blue", size= 14
, family = 'Arial'), tickfont = list(color = "blue", size = 14)),
yaxis = list(title = "Ecart ? la normale de la temp?rature moyenne
annuelle(en?C)", titlefont = list(color= "red", size= 14 , family =
'Arial'),
tickfont = list(color = "red", size = 14) , showline = TRUE, linecolor =
"red", linewidth = 2),
legend = list(x = 0.1, y = -0.3, font=list(size = 14,color=
"black")),margin = list(
t = 70,
r = 70,
b = 70,
l = 70
))
*file.copy("C:/Users/pc/Downloads/Evolution Tmoy.png",
paste("C:/MONOGRAPHIE/Resultats/Evolution Tmoy_",CPM[i,1],".png",sep="")*
*}*
Thank you very much in advance for any help.
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=04%7C01%7C%7C63572d98fe1f4af1938c08d8f2c57a0e%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637526277319446692%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=wwtfLAGJ3zjOzN%2FDxopVDEVnLC5QSF6H1ER6nHMEaLI%3D&reserved=0 PLEASE do read the posting guide https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.html&data=04%7C01%7C%7C63572d98fe1f4af1938c08d8f2c57a0e%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637526277319446692%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=nqKgiTsjQz%2FjF5gDRc1UMQiSxRdZCurArqyGz5pnNtg%3D&reserved=0 and provide commented, minimal, self-contained, reproducible code.
*Best Regards, * *Cordialement, ?? ???? ?????? * Rachida EL OUARAINI Service de la R?alisation des Mod?les Appliqu?s et de la T?l?d?tection Direction de la M?t?orologie Nationale du Maroc *T?l : +212 522 65 48 90* *Fax: +212 522 91 34 35* *"Your attitude, not your aptitude, will determine your altitude." Zig Ziglar* [[alternative HTML version deleted]]
Hi Jim, Many thanks for your answer ! I tried what you suggested but it doesn't work. I've got NO error message, but nothing happens at the end : no graphs ! It seems to me that the command "plot_ly" and the "for" loop DO NOT coexist, that's why I ask you how to overcome this problem? Thank you again Dr Jim.
On Tue, Mar 30, 2021 at 4:37 AM Jim Lemon <drjimlemon at gmail.com> wrote:
Hi Rachida,
My guess is that you create a vector of filenames:
filenames<-list.files(path="FicConfig",pattern="*.txt")
then use the filenames in the loop:
for(filename in filenames) {
nextfile<- read.table(filename, header = TRUE, sep = "\t" , dec =
",", skip = 0)
# do whatever you want with the resulting data frame here
# or perhaps save it into a list for processing later
}
Jim
On Tue, Mar 30, 2021 at 2:15 AM Rachida El Ouaraini
<elouaraini at gmail.com> wrote:
Hi everyone, I am new to R programming, and I am having difficulties modifying an R script to introduce the "for" loop in the code. While searching I found that this issue has already been raised, but I
did
not know what to do to fix mine !
*The code that works (without for command):*
CPM <- read.table("FicConfig/CPM.txt" , header = TRUE, sep = "\t" , dec =
",", skip = 0)
# The CPM.txt file containe 1 line
......................................................................
......................................................................
options(viewer = NULL)
plot_ly() %>%
htmlwidgets::onRender(
"function(el, x) {
var gd = document.getElementById(el.id);
Plotly.downloadImage(gd, {format: 'png', width: 1000, height: 700,
filename: 'AnomalieRR_EcartTmoy'});
}"
)%>%
add_trace(x =TAnn[ ,3], y = TAnn[ ,5], name = "Normale mensuelle de
Tmax(en ?C)",type = 'scatter', mode = 'markers', marker = list(size = T,
symbol = 'circle', color = ~TAnn[ ,5], line = list(width= 2, color =
cl)))
%>%
add_annotations(text = TAnn[ ,1], x= TAnn[ ,3], y = TAnn[ ,5], font =
list(color = "white", size = 14), showarrow = FALSE)%>%
layout(title = paste("Combinaison anomalie relative annuelle des
pr?cipitations et ?cart annuel ? la normale de la temp?rature moyenne ?
",CPM[1,1],sep =""),
xaxis = list(title = "Anomalie relative des pr?cipitations
annuelles(en %)", tickangle = 20 ,titlefont = list(color= "blue", size=
14
, family = 'Arial'), tickfont = list(color = "blue", size = 14)),
yaxis = list(title = "Ecart ? la normale de la temp?rature moyenne
annuelle(en?C)", titlefont = list(color= "red", size= 14 , family =
'Arial'),
tickfont = list(color = "red", size = 14) , showline = TRUE, linecolor =
"red", linewidth = 2),
legend = list(x = 0.1, y = -0.3, font=list(size = 14,color=
"black")),margin = list(
t = 70,
r = 70,
b = 70,
l = 70
))
*The code that does not work (with for command):*
CPM <- read.table("FicConfig/CPM.txt" , header = TRUE, sep = "\t" , dec =
",", skip = 0)
# The CPM.txt file containe several lines
*for (i in 1: (nrow(CPM))) {*
options(viewer = NULL)
plot_ly() %>%
htmlwidgets::onRender(
"function(el, x) {
var gd = document.getElementById(el.id);
Plotly.downloadImage(gd, {format: 'png', width: 1000, height: 700,
filename: 'AnomalieRR_EcartTmoy'});
}"
)%>%
add_trace(x =TAnn[ ,3], y = TAnn[ ,5], name = "Normale mensuelle de
Tmax(en ?C)",type = 'scatter', mode = 'markers', marker = list(size = T,
symbol = 'circle', color = ~TAnn[ ,5], line = list(width= 2, color =
cl)))
%>%
add_annotations(text = TAnn[ ,1], x= TAnn[ ,3], y = TAnn[ ,5], font =
list(color = "white", size = 14), showarrow = FALSE)%>%
layout(title = paste("Combinaison anomalie relative annuelle des
pr?cipitations et ?cart annuel ? la normale de la temp?rature moyenne ?
",CPM[i,1],sep =""),
xaxis = list(title = "Anomalie relative des pr?cipitations
annuelles(en %)", tickangle = 20 ,titlefont = list(color= "blue", size=
14
, family = 'Arial'), tickfont = list(color = "blue", size = 14)),
yaxis = list(title = "Ecart ? la normale de la temp?rature moyenne
annuelle(en?C)", titlefont = list(color= "red", size= 14 , family =
'Arial'),
tickfont = list(color = "red", size = 14) , showline = TRUE, linecolor =
"red", linewidth = 2),
legend = list(x = 0.1, y = -0.3, font=list(size = 14,color=
"black")),margin = list(
t = 70,
r = 70,
b = 70,
l = 70
))
*file.copy("C:/Users/pc/Downloads/Evolution Tmoy.png",
paste("C:/MONOGRAPHIE/Resultats/Evolution Tmoy_",CPM[i,1],".png",sep="")*
*}*
Thank you very much in advance for any help.
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
*Best Regards, * *Cordialement, ?? ???? ?????? * Rachida EL OUARAINI Service de la R?alisation des Mod?les Appliqu?s et de la T?l?d?tection Direction de la M?t?orologie Nationale du Maroc *T?l : +212 522 65 48 90* *Fax: +212 522 91 34 35* *?"Your attitude, not your aptitude, will determine your altitude." ?Zig Ziglar* [[alternative HTML version deleted]]
Hi! That is familiar: loop goes on, but nothing visual happens. Normally when I don't get output of the loop, I put the output-line inside the function print(), and it works. But in this case it probably doesn't help. I am sure that someone here can help you, Rachida. Mika L?hetetty Samsung Galaxy -?lypuhelimesta. -------- Alkuper?inen viesti -------- L?hett?j?: Rachida El Ouaraini <elouaraini at gmail.com> P?iv?m??r?: 30.3.2021 12.25 (GMT+02:00) Saaja: Mika Hamari <mika.hamari73 at outlook.com> Kopio: r-help at r-project.org Aihe: Re: [R] "for" loop does not work with my plot_ly command Hi Mika, and thank you very much for your answer. When I add the "for" loop to the code that produces before the graph I want, it does nothing : NO graph and NO error message. It seems to me that the command plot_ly and the for loop DO NOT coexist. Rachida
On Mon, Mar 29, 2021 at 7:44 PM Mika Hamari <mika.hamari73 at outlook.com<mailto:mika.hamari73 at outlook.com>> wrote:
Hi!
I am also learning, but I want try to help. I often use for-loop in R. I think that it could be due to dimensions of CPM, not the structure of the loop.
What kind of error message do you get? Is it: ?incorrect number of dimensions?? What happens if you substitute in the end instead of CPM[i,1] this:
file.copy("C:/Users/pc/Downloads/Evolution Tmoy.png",
paste("C:/MONOGRAPHIE/Resultats/Evolution Tmoy_",CPM[i],".png",sep="")
L?hett?j?: Rachida El Ouaraini<mailto:elouaraini at gmail.com>
L?hetetty: maanantai 29. maaliskuuta 2021 18.15
Vastaanottaja: r-help at r-project.org<mailto:r-help at r-project.org>
Aihe: [R] "for" loop does not work with my plot_ly command
Hi everyone,
I am new to R programming, and I am having difficulties modifying an R
script to introduce the "for" loop in the code.
While searching I found that this issue has already been raised, but I did
not know what to do to fix mine !
*The code that works (without for command):*
CPM <- read.table("FicConfig/CPM.txt" , header = TRUE, sep = "\t" , dec =
",", skip = 0)
# The CPM.txt file containe 1 line
......................................................................
......................................................................
options(viewer = NULL)
plot_ly() %>%
htmlwidgets::onRender(
"function(el, x) {
var gd = document.getElementById(el.id<https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fel.id%2F&data=04%7C01%7C%7Cd44ce15fde0549644d4e08d8f35dca77%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637526931442844620%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=Nn3hw1AfZso8HiTjtOYAEkzplnB3QRSrFQ5qoyNwJVA%3D&reserved=0>);
Plotly.downloadImage(gd, {format: 'png', width: 1000, height: 700,
filename: 'AnomalieRR_EcartTmoy'});
}"
)%>%
add_trace(x =TAnn[ ,3], y = TAnn[ ,5], name = "Normale mensuelle de
Tmax(en ?C)",type = 'scatter', mode = 'markers', marker = list(size = T,
symbol = 'circle', color = ~TAnn[ ,5], line = list(width= 2, color = cl)))
%>%
add_annotations(text = TAnn[ ,1], x= TAnn[ ,3], y = TAnn[ ,5], font =
list(color = "white", size = 14), showarrow = FALSE)%>%
layout(title = paste("Combinaison anomalie relative annuelle des
pr?cipitations et ?cart annuel ? la normale de la temp?rature moyenne ?
",CPM[1,1],sep =""),
xaxis = list(title = "Anomalie relative des pr?cipitations
annuelles(en %)", tickangle = 20 ,titlefont = list(color= "blue", size= 14
, family = 'Arial'), tickfont = list(color = "blue", size = 14)),
yaxis = list(title = "Ecart ? la normale de la temp?rature moyenne
annuelle(en?C)", titlefont = list(color= "red", size= 14 , family =
'Arial'),
tickfont = list(color = "red", size = 14) , showline = TRUE, linecolor =
"red", linewidth = 2),
legend = list(x = 0.1, y = -0.3, font=list(size = 14,color=
"black")),margin = list(
t = 70,
r = 70,
b = 70,
l = 70
))
*The code that does not work (with for command):*
CPM <- read.table("FicConfig/CPM.txt" , header = TRUE, sep = "\t" , dec =
",", skip = 0)
# The CPM.txt file containe several lines
*for (i in 1: (nrow(CPM))) {*
options(viewer = NULL)
plot_ly() %>%
htmlwidgets::onRender(
"function(el, x) {
var gd = document.getElementById(el.id<https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fel.id%2F&data=04%7C01%7C%7Cd44ce15fde0549644d4e08d8f35dca77%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637526931442854613%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=cjSxT%2BeaoRtlaDOKMHY910Pd0f8kJMVs35PErOpqfak%3D&reserved=0>);
Plotly.downloadImage(gd, {format: 'png', width: 1000, height: 700,
filename: 'AnomalieRR_EcartTmoy'});
}"
)%>%
add_trace(x =TAnn[ ,3], y = TAnn[ ,5], name = "Normale mensuelle de
Tmax(en ?C)",type = 'scatter', mode = 'markers', marker = list(size = T,
symbol = 'circle', color = ~TAnn[ ,5], line = list(width= 2, color = cl)))
%>%
add_annotations(text = TAnn[ ,1], x= TAnn[ ,3], y = TAnn[ ,5], font =
list(color = "white", size = 14), showarrow = FALSE)%>%
layout(title = paste("Combinaison anomalie relative annuelle des
pr?cipitations et ?cart annuel ? la normale de la temp?rature moyenne ?
",CPM[i,1],sep =""),
xaxis = list(title = "Anomalie relative des pr?cipitations
annuelles(en %)", tickangle = 20 ,titlefont = list(color= "blue", size= 14
, family = 'Arial'), tickfont = list(color = "blue", size = 14)),
yaxis = list(title = "Ecart ? la normale de la temp?rature moyenne
annuelle(en?C)", titlefont = list(color= "red", size= 14 , family =
'Arial'),
tickfont = list(color = "red", size = 14) , showline = TRUE, linecolor =
"red", linewidth = 2),
legend = list(x = 0.1, y = -0.3, font=list(size = 14,color=
"black")),margin = list(
t = 70,
r = 70,
b = 70,
l = 70
))
*file.copy("C:/Users/pc/Downloads/Evolution Tmoy.png",
paste("C:/MONOGRAPHIE/Resultats/Evolution Tmoy_",CPM[i,1],".png",sep="")*
*}*
Thank you very much in advance for any help.
______________________________________________
R-help at r-project.org<mailto:R-help at r-project.org> mailing list -- To UNSUBSCRIBE and more, see
https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=04%7C01%7C%7C63572d98fe1f4af1938c08d8f2c57a0e%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637526277319446692%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=wwtfLAGJ3zjOzN%2FDxopVDEVnLC5QSF6H1ER6nHMEaLI%3D&reserved=0<https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=04%7C01%7C%7Cd44ce15fde0549644d4e08d8f35dca77%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637526931442854613%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=yUnIowmFSSIERPTRbUO5IwV3N04x5shoKM%2BlgfNXxHY%3D&reserved=0>
PLEASE do read the posting guide https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.html&data=04%7C01%7C%7C63572d98fe1f4af1938c08d8f2c57a0e%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637526277319446692%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=nqKgiTsjQz%2FjF5gDRc1UMQiSxRdZCurArqyGz5pnNtg%3D&reserved=0<https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.html&data=04%7C01%7C%7Cd44ce15fde0549644d4e08d8f35dca77%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637526931442864610%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=8CDQ2TjGYzlPTPnzWQLWqM5ad3sOku8TaWqaUZlP8u0%3D&reserved=0>
and provide commented, minimal, self-contained, reproducible code.
--
Best Regards, Cordialement, ?? ???? ??????
Rachida EL OUARAINI
Service de la R?alisation des Mod?les Appliqu?s et de la T?l?d?tection
Direction de la M?t?orologie Nationale du Maroc
T?l : +212 522 65 48 90
Fax: +212 522 91 34 35
"Your attitude, not your aptitude, will determine your altitude." Zig Ziglar
Printing the return value of plot_ly and friends works for me in the
following examples:
# make base plot
p0 <- plotly::plot_ly(na.omit(palmerpenguins::penguins), x =
~bill_length_mm, y = ~body_mass_g)
# now add things to base plot
for(vrbl in list(~species, ~island, ~year)) {
tmp <- plotly::add_markers(p0, symbol=vrbl, color=vrbl)
print(tmp)
}
# or, the put the plots in a list
plots <- lapply(list(~species, ~island, ~year), function(vrbl)
plotly::add_markers(p0, symbol=vrbl, color=vrbl))
print(plots)
On Tue, Mar 30, 2021 at 2:26 AM Rachida El Ouaraini
<elouaraini at gmail.com> wrote:
Hi Mika, and thank you very much for your answer. When I add the "for" loop to the code that produces before the graph I want, it does nothing : NO graph and NO error message. It seems to me that the command plot_ly and the for loop DO NOT coexist. Rachida On Mon, Mar 29, 2021 at 7:44 PM Mika Hamari <mika.hamari73 at outlook.com> wrote:
Hi!
I am also learning, but I want try to help. I often use for-loop in R. I
think that it could be due to dimensions of CPM, not the structure of the
loop.
What kind of error message do you get? Is it: ?incorrect number of
dimensions?? What happens if you substitute in the end instead of CPM[i,1]
this:
file.copy("C:/Users/pc/Downloads/Evolution Tmoy.png",
paste("C:/MONOGRAPHIE/Resultats/Evolution Tmoy_",CPM[i],".png",sep="")
*L?hett?j?: *Rachida El Ouaraini <elouaraini at gmail.com>
*L?hetetty: *maanantai 29. maaliskuuta 2021 18.15
*Vastaanottaja: *r-help at r-project.org
*Aihe: *[R] "for" loop does not work with my plot_ly command
Hi everyone,
I am new to R programming, and I am having difficulties modifying an R
script to introduce the "for" loop in the code.
While searching I found that this issue has already been raised, but I did
not know what to do to fix mine !
*The code that works (without for command):*
CPM <- read.table("FicConfig/CPM.txt" , header = TRUE, sep = "\t" , dec =
",", skip = 0)
# The CPM.txt file containe 1 line
......................................................................
......................................................................
options(viewer = NULL)
plot_ly() %>%
htmlwidgets::onRender(
"function(el, x) {
var gd = document.getElementById(el.id);
Plotly.downloadImage(gd, {format: 'png', width: 1000, height: 700,
filename: 'AnomalieRR_EcartTmoy'});
}"
)%>%
add_trace(x =TAnn[ ,3], y = TAnn[ ,5], name = "Normale mensuelle de
Tmax(en ?C)",type = 'scatter', mode = 'markers', marker = list(size = T,
symbol = 'circle', color = ~TAnn[ ,5], line = list(width= 2, color = cl)))
%>%
add_annotations(text = TAnn[ ,1], x= TAnn[ ,3], y = TAnn[ ,5], font =
list(color = "white", size = 14), showarrow = FALSE)%>%
layout(title = paste("Combinaison anomalie relative annuelle des
pr?cipitations et ?cart annuel ? la normale de la temp?rature moyenne ?
",CPM[1,1],sep =""),
xaxis = list(title = "Anomalie relative des pr?cipitations
annuelles(en %)", tickangle = 20 ,titlefont = list(color= "blue", size= 14
, family = 'Arial'), tickfont = list(color = "blue", size = 14)),
yaxis = list(title = "Ecart ? la normale de la temp?rature moyenne
annuelle(en?C)", titlefont = list(color= "red", size= 14 , family =
'Arial'),
tickfont = list(color = "red", size = 14) , showline = TRUE, linecolor =
"red", linewidth = 2),
legend = list(x = 0.1, y = -0.3, font=list(size = 14,color=
"black")),margin = list(
t = 70,
r = 70,
b = 70,
l = 70
))
*The code that does not work (with for command):*
CPM <- read.table("FicConfig/CPM.txt" , header = TRUE, sep = "\t" , dec =
",", skip = 0)
# The CPM.txt file containe several lines
*for (i in 1: (nrow(CPM))) {*
options(viewer = NULL)
plot_ly() %>%
htmlwidgets::onRender(
"function(el, x) {
var gd = document.getElementById(el.id);
Plotly.downloadImage(gd, {format: 'png', width: 1000, height: 700,
filename: 'AnomalieRR_EcartTmoy'});
}"
)%>%
add_trace(x =TAnn[ ,3], y = TAnn[ ,5], name = "Normale mensuelle de
Tmax(en ?C)",type = 'scatter', mode = 'markers', marker = list(size = T,
symbol = 'circle', color = ~TAnn[ ,5], line = list(width= 2, color = cl)))
%>%
add_annotations(text = TAnn[ ,1], x= TAnn[ ,3], y = TAnn[ ,5], font =
list(color = "white", size = 14), showarrow = FALSE)%>%
layout(title = paste("Combinaison anomalie relative annuelle des
pr?cipitations et ?cart annuel ? la normale de la temp?rature moyenne ?
",CPM[i,1],sep =""),
xaxis = list(title = "Anomalie relative des pr?cipitations
annuelles(en %)", tickangle = 20 ,titlefont = list(color= "blue", size= 14
, family = 'Arial'), tickfont = list(color = "blue", size = 14)),
yaxis = list(title = "Ecart ? la normale de la temp?rature moyenne
annuelle(en?C)", titlefont = list(color= "red", size= 14 , family =
'Arial'),
tickfont = list(color = "red", size = 14) , showline = TRUE, linecolor =
"red", linewidth = 2),
legend = list(x = 0.1, y = -0.3, font=list(size = 14,color=
"black")),margin = list(
t = 70,
r = 70,
b = 70,
l = 70
))
*file.copy("C:/Users/pc/Downloads/Evolution Tmoy.png",
paste("C:/MONOGRAPHIE/Resultats/Evolution Tmoy_",CPM[i,1],".png",sep="")*
*}*
Thank you very much in advance for any help.
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=04%7C01%7C%7C63572d98fe1f4af1938c08d8f2c57a0e%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637526277319446692%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=wwtfLAGJ3zjOzN%2FDxopVDEVnLC5QSF6H1ER6nHMEaLI%3D&reserved=0 PLEASE do read the posting guide https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.html&data=04%7C01%7C%7C63572d98fe1f4af1938c08d8f2c57a0e%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637526277319446692%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=nqKgiTsjQz%2FjF5gDRc1UMQiSxRdZCurArqyGz5pnNtg%3D&reserved=0 and provide commented, minimal, self-contained, reproducible code.
--
*Best Regards, *
*Cordialement, ?? ???? ?????? *
Rachida EL OUARAINI
Service de la R?alisation des Mod?les Appliqu?s et de la T?l?d?tection
Direction de la M?t?orologie Nationale du Maroc
*T?l : +212 522 65 48 90*
*Fax: +212 522 91 34 35*
*"Your attitude, not your aptitude, will determine your altitude." Zig
Ziglar*
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.