Dear R list, I am a newbie to R and programming itself, so my question may be easy to answer for you. I wanted to create a scatterplot and i used the following code: par(mar=c(10, 4.1,4.1,2.1)) plot(q$location,q$points, , las=2, cex.axis=0.5,xlab="", ylab="" ) #location are character strings, there are about 70 locations #points are numeric, there are more than 4 points for every location my problem is that this code does not create a simple scatterplot with location on the x axis and points on the y axis. Instead of this i get "vertical boxplots" for every location. Thanks for any hint, Michael Graber
Hi On 24 Apr 2006 at 10:40, Michael Graber wrote: Date sent: Mon, 24 Apr 2006 10:40:42 +0200 From: Michael Graber <michael_graber at gmx.de> To: R-Mailingliste <r-help at stat.math.ethz.ch> Subject: [R] boxplots instead of a scatterplot> Dear R list, > > I am a newbie to R and programming itself, so my question may be easy > to answer for you. I wanted to create a scatterplot and i used the > following code: > > par(mar=c(10, 4.1,4.1,2.1)) > plot(q$location,q$points, , las=2, cex.axis=0.5,xlab="", ylab="" ) > > #location are character strings, there are about 70 locationslocation is probably a factor (not a character vector, try str(q) and look what is stated at location variable) so that's why R used boxplot automatically.> loc<-sample(letters[1:3],10, replace=T) > x<-rnorm(10) > plot(loc,x)Error in plot.window(xlim, ylim, log, asp, ...) : need finite 'xlim' values In addition: Warning messages: 1: NAs introduced by coercion 2: no finite arguments to min; returning Inf 3: no finite arguments to max; returning -Inf> plot(as.factor(loc),x)You can either: plot(as.numeric(q$location) ,q$points, , las=2, cex.axis=0.5,xlab="", ylab="" ) but you loose information about location names or to use stripchart> stripchart(split(x,loc), vertical=T)see ?stripchart HTH Petr> #points are numeric, there are more than 4 points for every location > > my problem is that this code does not create a simple scatterplot with > location on the x axis and points on the y axis. Instead of this i get > "vertical boxplots" for every location. > > Thanks for any hint, > > Michael Graber > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.htmlPetr Pikal petr.pikal at precheza.cz
Michael Graber wrote:> Dear R list, > > I am a newbie to R and programming itself, so my question may be easy to > answer for you. > I wanted to create a scatterplot and i used the following code: > > par(mar=c(10, 4.1,4.1,2.1)) > plot(q$location,q$points, , las=2, cex.axis=0.5,xlab="", ylab="" ) > > #location are character strings, there are about 70 locations > #points are numeric, there are more than 4 points for every location > > my problem is that this code does not create a simple scatterplot with > location on the x axis and points on the y axis. Instead of this i get > "vertical boxplots" for every location. >Hi Michael, R is probably trying to interpret the locations as a factor and helpfully breaking down the numeric variable by this factor. One way to get around this is to fake a numeric for the x axis by using the indices of the character variable for plotting, then cram in the labels using staxlab in the plotrix package: # nr.comb is an 'n choose r' function in a private package # I think there is an equivalent in gregmisc indies<-nr.comb(9,3)[1:70,] locations<- apply(indies,1,nonsense.words<-function(x) paste(LETTERS[x],sep="",collapse="")) testdf<-data.frame(locations=sample(locations,300,TRUE),numbers=rnorm(300)) location.indices<- sapply(testdf$locations,whichloc<-function(x) which(locations==x)) # leave lots of room for the labels x11(width=18,height=7) plot(location.indices,testdf$numbers,axes=FALSE) box() axis(2) # you can also try vertical labels using par staxlab(1,at=1:70,labels=locations,nlines=3) Jim