[R] Chart will not display

phii m@iii@g oii phiiipsmith@c@ phii m@iii@g oii phiiipsmith@c@
Wed Jun 3 03:46:21 CEST 2020

I have made what must be a simple mistake, but I have not been able to 
find it.

I create a function to plot a chart for a single variable. I want to 
display separate charts for several variables, one after another, with 
"Press [enter] to continue" in between. The function works fine for a 
single variable, but when I try to display several variables 
consecutively, using a for statement, no charts are displayed. The for 
statement executes without apparent error, but no charts appear.

Here is a reprex.

t <- c(1,2,3,4,5)
a <- c(1,4,5,8,7)
b <- c(2,2,5,3,1)
c <- c(3,6,2,8,3)
df <- data.frame(t=t,a=a,b=b,c=c)
df1 <- pivot_longer(df,cols=c(a,b,c),names_to="var",values_to="val")
chfn <- function(chnm) {
   ggplot(filter(df1,var==chnm),aes(x=t,y=val,group=1)) +
     geom_line() +
chfn("b") # test of the function - it works
chnms <- c("a","b","c")
for (i in chnms) {
   readline(prompt="Press [enter] to continue")

Thanks for your help.


More information about the R-help mailing list