Hi All,
I am trying to write down a script to simplify my work in making probability density charts for (prehistoric) calendar dates.
I wish to acknowledge the help received by Vinux in solving some issues deriving from my ggplot2 limited skill (this is the earlier thread).
The issue I am experiencing is that the command readline() does not wait for user to enter some values.
What puzzles me is that the piece of code that is not working is:
R does not wait for user's input, and skip directly to the next section.
I have tried to figure out where the issue is, trying to manually enter the code line by line, trying to test for possible conflict with ggplot2 or xlsx packages, etc etc. But I did not manage to spot the problem.
Another thing that puzzles me is that I used readline() previously in other scripts, and it worked as expected. So, I am wondering what is going wrong with this particular code. I bet it is something stupid, but I am not managing to spot it.
Any hint is welcome.
Thanks
Gm
p.s.
dataset attached
I am trying to write down a script to simplify my work in making probability density charts for (prehistoric) calendar dates.
I wish to acknowledge the help received by Vinux in solving some issues deriving from my ggplot2 limited skill (this is the earlier thread).
The issue I am experiencing is that the command readline() does not wait for user to enter some values.
What puzzles me is that the piece of code that is not working is:
Code:
answer <- readline(prompt="Do you want to set different limits for the x axis (y/n)? ")
I have tried to figure out where the issue is, trying to manually enter the code line by line, trying to test for possible conflict with ggplot2 or xlsx packages, etc etc. But I did not manage to spot the problem.
Another thing that puzzles me is that I used readline() previously in other scripts, and it worked as expected. So, I am wondering what is going wrong with this particular code. I bet it is something stupid, but I am not managing to spot it.
Any hint is welcome.
Thanks
Gm
p.s.
dataset attached
Code:
library(gglot2)
library(xlsx)
mydata <- read.xlsx(file.choose(), sheetIndex=1, header=TRUE)
plot.a <- ggplot(data=mydata)+ geom_line(aes(x=dates,y=prob,color=site))
plot.b <- ggplot(data=mydata)+geom_area(position="identity", aes(x=dates,y=prob,fill=site), alpha=0.5)
plot.c <- plot.a+geom_area(position="identity",aes(x=dates,y=prob,fill=site), alpha=0.5)
print(plot.a)
print(plot.b)
print(plot.c)
answer <- readline(prompt="Do you want to set different limits for the x axis (y/n)? ")
if (answer == "n") {
print("script ends: enjoy your plots")
} else {
c <- as.numeric(readline(prompt="Lower (i.e., left) limit? "))
d <- as.numeric(readline(prompt="Upper (i.e., right) limit? "))
plot.a.resized <- ggplot(data=mydata)+ geom_line(aes(x=dates,y=prob,color=site)) + scale_x_continuous (limits =c(c,d))
plot.b.resized <-ggplot(data=mydata)+geom_area(position="identity", aes(x=dates,y=prob,fill=site), alpha=0.5) + scale_x_continuous(limits =c(c,d))
plot.c.resized <- plot.a.resized+geom_area(position="identity",aes(x=dates,y=prob,fill=site), alpha=0.5)
print(plot.a.resized)
print(plot.b.resized)
print(plot.c.resized)
}