[R] Removing objects except user-defined functions
Dear R users. I would like to remove all object from my workspace except the function I have defined. However, is I use rm(list = ls()) everything is cleared. I was thinking to typeof to get information about objects, but I could not get it working right. Thank in advance, Phil [[alternative HTML version deleted]] __ R-help@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.
[R] Evaluating a formula
Hi all. How we evaluate a formula in R? Ex.: params - list(a = 2, b = 3) x - seq(1,10, length.out = 100) func1 - as.formula(y ~ a*x^2 + b*x) ##How to evaluate func1 using x and the params list ??? Thank you in advance, Phil [[alternative HTML version deleted]] __ R-help@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.
[R] Substitute initial guesses of parameters in a function
Hi everyone, I have a formula like this: f - as.formula(y ~ p0a * exp(-0.5 * ((x - p1a)/p2a)^2)) I would like to dynamically provide starting values for p0a, p1a, p2a. Is there a way to do it? #Params estimates p - c(12, 10, 1) # This is where I have difficulties mystart - substitute(...) nls(formula = f, start = mystart) Regards, Philippe [[alternative HTML version deleted]] __ R-help@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.
Re: [R] Substitute initial guesses of parameters in a function
Thank you! Date: Wed, 3 Dec 2014 08:02:17 -0500 From: murdoch.dun...@gmail.com To: pmassico...@hotmail.com; r-help@r-project.org Subject: Re: [R] Substitute initial guesses of parameters in a function On 03/12/2014 7:37 AM, philippe massicotte wrote: Hi everyone, I have a formula like this: f - as.formula(y ~ p0a * exp(-0.5 * ((x - p1a)/p2a)^2)) I would like to dynamically provide starting values for p0a, p1a, p2a. Is there a way to do it? Just give a named vector of starting values. #Params estimates p - c(12, 10, 1) Should be p - c(p0a = 12, p1a = 10, p2a = 1) # This is where I have difficulties mystart - substitute(...) nls(formula = f, start = mystart) Now start = p will work. No need to mess with substitute. (And no need to use as.formula on the very first line; that's already a formula.) Duncan Murdoch Regards, Philippe [[alternative HTML version deleted]] __ R-help@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. [[alternative HTML version deleted]] __ R-help@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.
[R] Formula with dynamic number of variables
Hi everyone. I have a non-linear model specified as this (6 variables, a0, S, K, p0, p1, p2): fit - nlsLM(formula = dat ~ a0 * exp(-S*(x - 250)) + K + ( C ) ) where C = (p0*exp(-0.5*((x-p1)/p2)^2)) The problem is that I do not know in advance how many component (C) I will have in the model. That means It could be: nlsLM(formula = dat ~ a0 * exp(-S*(x - 250)) + K + ( (p0*exp(-0.5*((x-p1)/p2)^2)) ) ) or nlsLM(formula = dat ~ a0 * exp(-S*(x - 250)) + K + ( (p0*exp(-0.5*((x-p1)/p2)^2)) ) + ( (p0b*exp(-0.5*((x-p1b)/p2b)^2)) )) or nlsLM(formula = dat ~ a0 * exp(-S*(x - 250)) + K + ( (p0*exp(-0.5*((x-p1)/p2)^2)) ) + ( (p0b*exp(-0.5*((x-p1b)/p2b)^2)) + ( (p0c*exp(-0.5*((x-p1c)/p2c)^2 So I was wondering if it was possible to dynamically build the formula that I will use in my model? The first part of my model will always be a0 * exp(-S*(x - 250)) + K, I just want to add a certain number of components dynamically. I guess it will be related with reformulate() but I can't not find how to make it works. Thank you for your help, Philippe [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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.
[R] legend position
Hi all. I'm ploting a raster and I can't find the proper way to move the legend. For example, r = raster(system.file(external/test.grd, package=raster))plot(r) How can I put the legend at the desired position? Thank in advance,Phil [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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.
Re: [R] legend position
Thank you for reply. If I'm not wrong, legend(...) will works for discrete elements. I'm not sure hot to use it for a colorbar legend sur as the one in the example bellow. Phil Date: Mon, 2 Dec 2013 11:49:19 -0800 From: c...@witthoft.com To: r-help@r-project.org Subject: Re: [R] legend position See ?legend . you can add a legend directly to an existing plot. An example: legend('topright',c('hot','cold'),lty=1,col=c('red','green'),bg='white') Now if you're trying to place the legend outside the plot area (i.e. in some other part of the window), you'll need to invoke par(xpd=TRUE) . See the help at ?par . Filoche wrote Hi all. I'm ploting a raster and I can't find the proper way to move the legend. For example, r = raster(system.file(external/test.grd, package=raster))plot(r) How can I put the legend at the desired position? Thank in advance,Phil [[alternative HTML version deleted]] __ R-help@ mailing list 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. -- View this message in context: http://r.789695.n4.nabble.com/legend-position-tp4681489p4681492.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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.
Re: [R] legend position
Thank you, I'll try to work with lattice. Regards,Phil Date: Mon, 2 Dec 2013 12:06:50 -0800 From: c...@witthoft.com To: r-help@r-project.org Subject: Re: [R] legend position It occurs to me that perhaps you're referring to the 'color bar' on the right of the plot. AFAIK you cannot get at that from the raster::plot method. However lattice::levelplot does allow you to manipulate or remove that colorbar. -- View this message in context: http://r.789695.n4.nabble.com/legend-position-tp4681489p4681497.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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.
Re: [R] legend position
Thank you David, it is exactly what I needed. Regards,Phil From: dcarl...@tamu.edu To: pmassico...@hotmail.com; r-help@r-project.org Subject: RE: [R] legend position Date: Mon, 2 Dec 2013 14:29:06 -0600 It is not straightforward unless you want the legend in the right or the bottom margins. To put the legend inside the plot region it is simplest to use image() to plot the raster file and then image.plot(legend.only=TRUE) to add the legend. In addition to reading the help page for plot{raster}, you also need the pages for image{raster} and image.plot{fields}. Here are two simple examples. image(r, col=rev(terrain.colors(255))) plot(r, horizontal=TRUE, smallplot=c(.15, .5, .84, .86), legend.only=TRUE) image(r, col=rev(terrain.colors(255))) plot(r, smallplot=c(.15, .17, .5, .85), legend.only=TRUE) - David L Carlson Department of Anthropology Texas AM University College Station, TX 77840-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of philippe massicotte Sent: Monday, December 2, 2013 1:22 PM To: r-help@r-project.org Subject: [R] legend position Hi all. I'm ploting a raster and I can't find the proper way to move the legend. For example, r = raster(system.file(external/test.grd, package=raster))plot(r) How can I put the legend at the desired position? Thank in advance,Phil [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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.
[R] data manipulation
Hi everyone. I have a list like this: neutral_classes = list(A = 71:100, B = 46:70, C = 21:45, D = 0:20) and I'm trying to return the letter of the named vector for with an integer belong. For example, B if I use the value 50. Any help would be greatly appreciated. Regards,Phil [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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.
Re: [R] data manipulation
Thank you everyone for your suggestions. Date: Fri, 22 Nov 2013 18:04:16 + From: pbu...@pburns.seanet.com To: pmassico...@hotmail.com; r-help@r-project.org Subject: Re: [R] data manipulation The final ) went missing in the command starting 'names(neutralVec) - '. On 22/11/2013 17:51, Patrick Burns wrote: I think a list is the wrong structure, a vector would be better since you can use 'match': # transform data structure: neutralVec - unlist(neutral_classes) names(neutralVec) - names(neutral_classes[rep(1:length(neutral_classes), sapply(neutral_classes, length))] # get one or more results with 'match': names(neutralVec[match(c(50, 20, 10, -4), neutralVec)]) # result: # [1] B D D NA Pat On 22/11/2013 16:58, philippe massicotte wrote: Hi everyone. I have a list like this: neutral_classes = list(A = 71:100, B = 46:70, C = 21:45, D = 0:20) and I'm trying to return the letter of the named vector for with an integer belong. For example, B if I use the value 50. Any help would be greatly appreciated. Regards,Phil [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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. -- Patrick Burns pbu...@pburns.seanet.com twitter: @burnsstat @portfolioprobe http://www.portfolioprobe.com/blog http://www.burns-stat.com (home of: 'Impatient R' 'The R Inferno' 'Tao Te Programming') [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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.
Re: [R] data manipulation
Hi again. I realized that the example I give is not valid, because the number I'm using is not an integer (ex. 50.1). So I thought using is.between = function(x, a, b) { (x - a) * (b - x) 0} But I'm not sure how to use it with lapply to avoid looping in my code. Regards,Phil From: pmassico...@hotmail.com To: r-help@r-project.org Date: Fri, 22 Nov 2013 18:17:03 + Subject: Re: [R] data manipulation Thank you everyone for your suggestions. Date: Fri, 22 Nov 2013 18:04:16 + From: pbu...@pburns.seanet.com To: pmassico...@hotmail.com; r-help@r-project.org Subject: Re: [R] data manipulation The final ) went missing in the command starting 'names(neutralVec) - '. On 22/11/2013 17:51, Patrick Burns wrote: I think a list is the wrong structure, a vector would be better since you can use 'match': # transform data structure: neutralVec - unlist(neutral_classes) names(neutralVec) - names(neutral_classes[rep(1:length(neutral_classes), sapply(neutral_classes, length))] # get one or more results with 'match': names(neutralVec[match(c(50, 20, 10, -4), neutralVec)]) # result: # [1] B D D NA Pat On 22/11/2013 16:58, philippe massicotte wrote: Hi everyone. I have a list like this: neutral_classes = list(A = 71:100, B = 46:70, C = 21:45, D = 0:20) and I'm trying to return the letter of the named vector for with an integer belong. For example, B if I use the value 50. Any help would be greatly appreciated. Regards,Phil [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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. -- Patrick Burns pbu...@pburns.seanet.com twitter: @burnsstat @portfolioprobe http://www.portfolioprobe.com/blog http://www.burns-stat.com (home of: 'Impatient R' 'The R Inferno' 'Tao Te Programming') [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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.
[R] Trying to avoid nested loop
Dear R users. I'm trying to avoid using nested loops in the following code but I'm not sure how to proceed. Any help would be greatly appreciated. With regards,Phil X = matrix(rnorm(100), 10, 10) ## Version with nested loopsresult = 0 for(m in 1:nrow(X)){ for(n in 1:ncol(X)){if(X[m,n] != 0){ result = result + (X[m,n] / (1 + abs(m - n)))} }} ## No loop-sum(ifelse(M 0, M/??? , 0)) [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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.
Re: [R] Trying to avoid nested loop
Thank you for your answer. This is what I needed. From: s.elli...@lgcgroup.com To: r-help@r-project.org Date: Fri, 4 Oct 2013 15:13:49 +0100 Subject: Re: [R] Trying to avoid nested loop I'm trying to avoid using nested loops in the following code but I'm not sure how to proceed. Any help would be greatly appreciated. With regards,Phil X = matrix(rnorm(100), 10, 10) result = 0 for(m in 1:nrow(X)){ for(n in 1:ncol(X)){ if(X[m,n] != 0){ result = result + (X[m,n] / (1 + abs(m - n))) } } } First, you don't need the 'if', do you? If X[m,n]==0 (rare for a floating point number) (X[m,n] / (1 + abs(m - n)) will be zero anyway. Then, depending on the matrix size, you can probably do the whole thing using an index array. Something like: idx - as.matrix( expand.grid(1:nrow(X), 1:ncol(X)) ) result - sum( X[idx] / apply(idx,1, function(x) 1+abs(diff(x))) ) #... which seemed to do the identically the same thing as your loop when I tried it. S Ellison *** This email and any attachments are confidential. Any use...{{dropped:8}} __ R-help@r-project.org mailing list 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. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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.
[R] Combining rasters
Hi everyone. I would like to know if it is possible to combine rasters in R to form a collage. For example, I would like to place 2 copies of the R logo side by side. r = raster(system.file(external/rlogo.grd, package = raster)) After reading the help file (maybe I missed it) I did not find a way to do it. Any help would be appreciated. Sincerely, Phil __ R-help@r-project.org mailing list 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.
Re: [R] Problem with converting F to FALSE
Look at colClasses in ?read.csv Date: Thu, 5 Sep 2013 18:14:49 +0530 From: kiran4u2...@gmail.com To: r-help@r-project.org Subject: [R] Problem with converting F to FALSE Hi, I have a peculier problem in R-Project that is when my CSV file have one column with all values as 'F' the R-Project converting this 'F' to FALSE. Can some one please suggest how to stop this convertion. Because I want to use 'F' in my calculations and show it in screen. for example my data is like sex group F 1 F 2 F 3 but when I use read.csv and load the csv file data is converting it to sex group FALSE 1 FALSE 2 FALSE 3 but i want it as source data like sex group F 1 F 2 F 3 Thanks in advance, D V Kiran Kumar [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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.
[R] Histogram
Hi everyone. I'm currently translating some Matlab code into R. However, I realized that the hsit function produce different results in both languages. in Matlab, hist(1:10, 10) will produce 10 bins with a count of 1 in each, but in R it will produce 9 classes with count of 2,1,1,1,1,1,1,1,1. I'm a bit embarrassed to ask such question, but why R is not producing 10 classes as requested? Thanks in advance,Phil [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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.
Re: [R] Histogram
Thank you everyone for your help. Date: Wed, 4 Sep 2013 20:00:02 -0400 From: murdoch.dun...@gmail.com To: dcarl...@tamu.edu CC: pmassico...@hotmail.com; ruipbarra...@sapo.pt; r-help@r-project.org Subject: Re: [R] Histogram On 13-09-04 4:44 PM, David Carlson wrote: Good question. It turns out that the manual page does not tell the whole story. Do you really think the manual page would be improved if it went into as much detail as you give below? It does say clearly that breaks is a suggestion only. I don't think it would be clearer if it explained exactly how the suggestion is used. It would just be more complicated, and less likely to be read. Duncan Murdoch Looking at the source code for hist.default, the function starts with the number of breaks suggested by nclass.Sturges(), but then this number (or any other number of breaks that you specify) is passed to pretty() along with the maximum and the minimum values of the data (ie range(data)) to create pretty break intervals. In your example, nclass.Sturges() always recommends 8 breaks, but the number of the breaks changes based on the minimum and maximum values. So the only way to get exactly the number of breaks you want is to specify the break intervals yourself. David Carlson -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of philippe massicotte Sent: Wednesday, September 4, 2013 3:02 PM To: Rui Barradas Cc: r-help@R-project.org Subject: Re: [R] Histogram Thank you everyone. Try executing this: replicate(100, length(hist(rnorm(100), nclass = 10)$counts)) I'm still not sure why the number of bins (classes) is not consistent. Thank in advance. Date: Wed, 4 Sep 2013 20:27:36 +0100 From: ruipbarra...@sapo.pt To: pmassico...@hotmail.com CC: r-help@r-project.org Subject: Re: [R] Histogram Hello, See the arguments 'right' and 'include.lowest' of ?hist. To give what you want, try instead h1 - hist(1:10, 10) # counts are 2, 1, 1, ... h2 - hist(1:10, breaks = 0:10) # all counts are 1 and see the difference between h1 and h2, components 'breaks' and 'counts'. Hope this helps, Rui Barradas Em 04-09-2013 19:34, philippe massicotte escreveu: Hi everyone. I'm currently translating some Matlab code into R. However, I realized that the hsit function produce different results in both languages. in Matlab, hist(1:10, 10) will produce 10 bins with a count of 1 in each, but in R it will produce 9 classes with count of 2,1,1,1,1,1,1,1,1. I'm a bit embarrassed to ask such question, but why R is not producing 10 classes as requested? Thanks in advance,Phil [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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. __ R-help@r-project.org mailing list 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. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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.
[R] RCurl and google trends
Dear R users. We are currently developing a R package (GTrendsR) that allows to retrieve data from google trends. To do so, Im using the RCurl library. At this point everything works perfectly (i.e. the data obtained from R is identical to the data obtained directly from the web site). However, after 5-10 queries I get a quota excess limit message. If I log manually on google trend web site, it still works (i.e. no quota problems). So, that let me think it must be something related to the way I connect to google with R. More specifically, I suspect it something about how I define the connection with curlSetOpt in relation with cookies. I know it might not be obvious, but if someone has an idea :) Heres my code. gConnect = function(usr, psw) { loginURL - https://accounts.google.com/accounts/ServiceLogin; authenticateURL - https://accounts.google.com/accounts/ServiceLoginAuth; ch - getCurlHandle() curlSetOpt(curl = ch, ssl.verifypeer = FALSE, useragent = Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13, followlocation = TRUE, cookiejar = ./cookies, cookiefile = ./cookies) ## Google Account login loginPage - getURL(loginURL, curl = ch) galx.match - str_extract(string = loginPage, pattern = ignore.case('name=GALX\\s*value=([^]+)')) galx - str_replace(string = galx.match, pattern = ignore.case('name=GALX\\s*value=([^]+)'), replacement = \\1) authenticatePage - postForm(authenticateURL, .params = list(Email = usr, Passwd = psw, GALX = galx), curl = ch, .opts = list(verbose = F)) return(ch) } With regards, Phil -- Philippe Massicotte, Ph. D. Stagiaire postdoctoral Postdoctoral Research Fellow Université du Québec à Trois-Rivières (UQTR) Département de Chimie-Biologie Centre de Recherche sur les Interactions Bassins Versants- Écosystèmes aquatiques (RIVE) Pavillon Léon-Provancher Local 3413 3351, boul. des Forges CP 500 Trois-Rivières (QC) G9A 5H7 CANADA Tel: (819) 376-5011 #3402 Fax: (819) 376-5084 Courriel: philippe.massico...@uqtr.ca Web site : http://anotherrblog.blogspot.ca/ http://anotherrblog.blogspot.ca/ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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.
[R] Fine control of plot
Hi everyone. I'm trying to create a graph where I could plot some lines on the right side. Here an example: layout(matrix(c(1,2), 1, 2, byrow = TRUE), widths=c(6,2), heights=c(1,1)) x = 1:100y = rnorm(x)+xplot(x,y) reg = lm(y~x)abline(reg, col = red) plot(1, type=n, axes=F, xlab=, ylab=, xlim = c(-1,1), ylim = c(min(y), max(x)))segments(-0.25,min(reg$fitted.values),0.25,min(reg$fitted.values))segments(-0.25,max(reg$fitted.values),0.25,max(reg$fitted.values))segments(0,min(reg$fitted.values),0,max(reg$fitted.values)) However, I cant figure out how to make it a bit nicer by removing extra space to the right. Any help would be greatly appreciated. Regards,Phil [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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.
Re: [R] Fine control of plot
Hi and thank you for your answer. Sorry for the html post, here's the code: (you missed a break line between +x and plot(...) layout(matrix(c(1,2), 1, 2, byrow = TRUE), widths=c(6,2), heights=c(1,1)) x = 1:100 y = rnorm(x)+x plot(x,y) reg = lm(y~x) abline(reg, col = red) plot(1, type=n, axes=F, xlab=, ylab=, xlim = c(-1,1), ylim = c(min(y), max(x))) segments(-0.25,min(reg$fitted.values),0.25,min(reg$fitted.values)) segments(-0.25,max(reg$fitted.values),0.25,max(reg$fitted.values)) segments(0,min(reg$fitted.values),0,max(reg$fitted.values)) I hope my question is more obvious after you urn this example. Regards, Phil Date: Tue, 12 Mar 2013 15:33:40 -0400 Subject: Re: [R] Fine control of plot From: sarah.gos...@gmail.com To: pmassico...@hotmail.com CC: r-help@r-project.org Hi, You posted in HTML by mistake, so your code was mangled: I'm trying to create a graph where I could plot some lines on the right side. Here an example: layout(matrix(c(1,2), 1, 2, byrow = TRUE), widths=c(6,2), heights=c(1,1)) x = 1:100y = rnorm(x)+xplot(x,y) reg = lm(y~x)abline(reg, col = red) plot(1, type=n, axes=F, xlab=, ylab=, xlim = c(-1,1), ylim = c(min(y), max(x)))segments(-0.25,min(reg$fitted.values),0.25,min(reg$fitted.values))segments(-0.25,max(reg$fitted.values),0.25,max(reg$fitted.values))segments(0,min(reg$fitted.values),0,max(reg$fitted.values)) I figured out where the linebreaks go, but I can't run this: y = rnorm(x)+xplot(x,y) What's xplot() doing here? However, I cant figure out how to make it a bit nicer by removing extra space to the right. Can you explain further what you're trying to do? Plot spacing is controlled with par() for base graphics, but I really don't understand what you're after. -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list 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.
Re: [R] Fine control of plot
xpd=TRUE might works well. I'll give it a try. Thank you for your assistance, Phil Date: Tue, 12 Mar 2013 16:07:05 -0400 Subject: Re: [R] Fine control of plot From: sarah.gos...@gmail.com To: pmassico...@hotmail.com CC: r-help@r-project.org Okay, so what you really want to do is be able to set a wide right margin and draw some segments there? Using layout() is not the best way to go about this: as you've discovered, you can't control the area assigned. You can cheat with layout(), as in: layout(matrix(c(1,1,1,2), nrow=1)) but the better way is to see xpd within ?par as described here: https://stat.ethz.ch/pipermail/r-help/2009-July/206311.html along with par()$mai to set the margins appropriately. Sarah On Tue, Mar 12, 2013 at 3:50 PM, philippe massicotte pmassico...@hotmail.com wrote: Hi and thank you for your answer. Sorry for the html post, here's the code: (you missed a break line between +x and plot(...) layout(matrix(c(1,2), 1, 2, byrow = TRUE), widths=c(6,2), heights=c(1,1)) x = 1:100 y = rnorm(x)+x plot(x,y) reg = lm(y~x) abline(reg, col = red) plot(1, type=n, axes=F, xlab=, ylab=, xlim = c(-1,1), ylim = c(min(y), max(x))) segments(-0.25,min(reg$fitted.values),0.25,min(reg$fitted.values)) segments(-0.25,max(reg$fitted.values),0.25,max(reg$fitted.values)) segments(0,min(reg$fitted.values),0,max(reg$fitted.values)) I hope my question is more obvious after you urn this example. Regards, Phil Date: Tue, 12 Mar 2013 15:33:40 -0400 Subject: Re: [R] Fine control of plot From: sarah.gos...@gmail.com To: pmassico...@hotmail.com CC: r-help@r-project.org Hi, You posted in HTML by mistake, so your code was mangled: I'm trying to create a graph where I could plot some lines on the right side. Here an example: layout(matrix(c(1,2), 1, 2, byrow = TRUE), widths=c(6,2), heights=c(1,1)) x = 1:100y = rnorm(x)+xplot(x,y) reg = lm(y~x)abline(reg, col = red) plot(1, type=n, axes=F, xlab=, ylab=, xlim = c(-1,1), ylim = c(min(y), max(x)))segments(-0.25,min(reg$fitted.values),0.25,min(reg$fitted.values))segments(-0.25,max(reg$fitted.values),0.25,max(reg$fitted.values))segments(0,min(reg$fitted.values),0,max(reg$fitted.values)) I figured out where the linebreaks go, but I can't run this: y = rnorm(x)+xplot(x,y) What's xplot() doing here? However, I cant figure out how to make it a bit nicer by removing extra space to the right. Can you explain further what you're trying to do? Plot spacing is controlled with par() for base graphics, but I really don't understand what you're after. -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list 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.
[R] Combining boxplot
Hi everyone. I have two data frames that contain the same variables but with different number of observation. I would like to know it was possible to combine the data so I can have paired boxplot on the same figure. For example, df1 = data.frame(x = rnorm(100)) df1$type = ifelse(df1$x = 0 , type1, type2) df2 = data.frame(x = rnorm(50,0,2)) df2$type = ifelse(df2$x = 0 , type1, type2) ## How to combine boxplot boxplot(df1$x~df1$type) boxplot(df2$x~df2$type) df1 would be observed data whereas df2 would be simulated data. I would like to have the two categories (type1 and type2) on x axis and a colour to differentiate simulated vs observed datra. Regards, Phil __ R-help@r-project.org mailing list 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.
[R] Help with layout
Dear R users. I'm new with layout and I can't figure how to teak my graphs. I have the following code: layout(matrix(c(1,2,3), 3, 1, byrow = TRUE), heights=c(0.3,0.3,0.6)) boxplot(rnorm(100), horizontal=TRUE, axes=FALSE) boxplot(rnorm(100), horizontal=TRUE, axes=FALSE) hist(rnorm(100)) Is it possible to have the two horizontal boxplot closer to each other? With regards, Phil [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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.