[R] plot.window arguments being ignored?
Viknesh
viknesh at stat.ufl.edu
Sun Nov 8 00:45:33 CET 2009
Hi Dan,
I think it's because lines() is meant for you to add lines to a plot. Hence
it does not make R redraw the plot. If you wish to set the limits of the
y-axis (or x-axis for that matter), you should do it in the plot function
call, and then call lines() without the "ylim=ry" part. So your final two
lines could look like this:
plot(time_for_graph[,1], preference_for_graph[,1], type="b", xlim=rx,
ylim= ry, xlab="Time", ylab="Preference")
lines(time_for_graph[,1], preference_for_graph[,2], type="b", col="red")
HTH,
Vik
---
Grad Student
Department of Statistics
University of Florida
ARRRRR_user wrote:
>
> Hi,
> Why, when I run the script below, is my y-axis range command being
> ignored? I.e., the y axis graphed consistently fits the line specified in
> the plot command, but never fits the line I'm trying to add in the
> subsequent line command.
> This is my first R script, so if I'm doing anything else wacky that jumps
> out, please let me know. I'm an advanced Stata user, but R is new to me.
> The script is designed to simulate a binary-choice decision field theory
> example with internally-controlled stop time, as per Neural Networks 19
> (2006) 1047-1058.
> Thanks in advance!!
> -Dan
>
>
> #-----------------
> # Starting preference state; two choices
> preference<-c(0,0)
> # Preference threshold; when one of the preference states exceeds this
> threshhold, deliberation stops
> theta<- 2
> # Contrast matrix
> contrast<-array(c(1, -1, -1, 1), dim=c(2,2))
> # Value Matrix; three possible states of the world
> value<-array(c(1,0, 0, 1, .5,.5), dim=c(2, 3))
> # Feedback Matrix
> feedback<-array(c(1, .5, .5, 1), dim=c(2,2))
>
> # Time
> t<- array(0, dim=c(1,1))
>
> # Arrays to keep track of history for graphing
> time_for_graph<-array(t, dim=c(1,1))
> preference_for_graph<-array(preference, dim=c(1,2))
>
> # Moving through time until preference crosses the threshold theta
> while (preference[1]<theta && preference[2]<theta) {
>
> #stochastic weights for this time period
> weight<-rnorm(3,0,1)
>
> #updating preference
> preference<-feedback%*%preference + contrast%*%value%*%weight
>
> #updating history
> t<-t+1
> time_for_graph<-rbind(time_for_graph, t)
> preference_for_graph<-rbind(preference_for_graph, array(preference,
> dim=c(1,2)))
>
> #updating graph ranges
> ry<-range(preference_for_graph)
> rx<-range(time_for_graph)
>
> #updating graph
> plot(time_for_graph[,1], preference_for_graph[,1], type="b",
> plot.window(rx, ry), xlab="Time", ylab="Preference")
> lines(time_for_graph[,1], preference_for_graph[,2], type="b", col="red",
> ylim=ry)
> }
> #-------------
>
--
View this message in context: http://old.nabble.com/plot.window-arguments-being-ignored--tp26249609p26249696.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list