Re: [R] Vary an equation using values from a sequence
Thank you, I�ll give it a try. Jake Get Outlook for iOS<https://aka.ms/o0ukef> From: Bert Gunter Sent: Thursday, March 15, 2018 3:23:18 PM To: Jake William Andrae Cc: R-help Subject: Re: [R] Vary an equation using values from a sequence I thnk what you want is ?outer. e.g.: outer(Data -min(Data),value,FUN = "+") Whether this works for your real task, however, may depend on details and complexities that you have omitted. Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Wed, Mar 14, 2018 at 9:14 PM, Jake William Andrae mailto:jake.and...@adelaide.edu.au>> wrote: Hi All, I have a vector of data on which I am operating. The equation with which I want to operate on the vector has a value k. I want to run the equation and output a new vector, each time replacing k with each value from the sequence I defined. I have thought about using for loops and such, but this seems like overkill. I am wondering if there is a simple solution that would allow me to accomplish this. The code I am using is outlined below. Data <- c(1:10) #Data value <- seq(from = 0, to = 100 , by = 0.01) #Sequence Data - min(Data) + k # Equation Thanks, Jake Jake Andrae PhD Candidate Geology & Geophysics � Sprigg Geobiology Centre Department of Earth Science School of Physical Sciences The University of Adelaide, AUSTRALIA 5005 Phone: 0407701565 Email: jake.and...@adelaide.edu.au<mailto:jake.and...@adelaide.edu.au> [[alternative HTML version deleted]] __ R-help@r-project.org<mailto: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] Vary an equation using values from a sequence
Hi All, I have a vector of data on which I am operating. The equation with which I want to operate on the vector has a value k. I want to run the equation and output a new vector, each time replacing k with each value from the sequence I defined. I have thought about using for loops and such, but this seems like overkill. I am wondering if there is a simple solution that would allow me to accomplish this. The code I am using is outlined below. Data <- c(1:10) #Data value <- seq(from = 0, to = 100 , by = 0.01) #Sequence Data - min(Data) + k # Equation Thanks, Jake Jake Andrae PhD Candidate Geology & Geophysics � Sprigg Geobiology Centre Department of Earth Science School of Physical Sciences The University of Adelaide, AUSTRALIA 5005 Phone: 0407701565 Email: jake.and...@adelaide.edu.au [[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] Help with marmap package
Hello, I'm using the 'Marmap' R package to create ocean bathymetry maps. I've managed quite well, but I'm having a little difficulty with setting my x-axis (longitude) limits. When I run the code, the map is projected with large white bands on either side of the desired longitude limits. I've tried setting the limits myself (i.e xlim = c(115, 130)). I've also tried setting the 'xaxs' parameter to 'i', with no luck. I've included the code below, with the NOAA bathymetry data I'm trying to map. If anyone has had any experience with this package and has encountered similar problems and has a solution, I'd love to hear about it. # Load package library(marmap) # Import bathymetry bat <- getNOAA.bathy(130, 115, -26, -12, res = 1, keep = TRUE) # Plot map with isobaths every 1000m plot(bat, image = TRUE, land = TRUE, deep=-1, shallow=-1000, step=1000, drawlabels = TRUE, bpal = list(c(min(bat,na.rm=TRUE), 0, blues), c(0, max(bat, na.rm=TRUE), greenbrowns)), lwd = 0.1, col = 'grey20') Regards, Jake Andrae PhD Candidate Geology & Geophysics � Sprigg Geobiology Centre Department of Earth Science School of Physical Sciences The University of Adelaide, AUSTRALIA 5005 Phone: 0407701565 Email: jake.and...@adelaide.edu.au [[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] Superscript in graph text
Thank you, your suggestions are very helpful. As I said, I'm a novice to R and this list, and it's hard for me to decipher exactly what is required; I was really hoping for some basic script formatting guidance (which was given and appreciated). Jake Andrae PhD Candidate Geology & Geophysics � Sprigg Geobiology Centre Department of Earth Science School of Physical Sciences The University of Adelaide, AUSTRALIA 5005 Phone: 0407701565 Email: jake.and...@adelaide.edu.au From: Richard M. Heiberger Sent: Thursday, 19 January 2017 12:58 PM To: Jake William Andrae Subject: Re: [R] Superscript in graph text your example is not reproducible because I don't have your dataset. Please re-read the notes at the bottom of every R-help email PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. The convention on this email list is to always stay on the list. It is not good form to write only to the person who replies to you and the list. For base graphics, you can use an expression or bquote in any of the annotation arguments or functions. I showed you a use in main=. It works the same for all others. plot(1:10) p <- .4 R2 <- .9876 mtext(bquote(p * " = " * .(p)), adj=0, line=0.1, col="black", cex=0.7) mtext(bquote(R^2 * " =" * .(R2)), adj=0, line=1, col="black", cex=0.7) ## Using mtext doesn't look like a good idea. ## use sub or main or some other keywords title(main=bquote(p * " = " * .(p)), sub=bquote(R^2 * "/" * p * " = " * .(R2/p))) ## Or do it all together p <- .4 R2 <- .9876 plot(1:10, main=bquote(p * " = " * .(p)), sub=bquote(R^2 * "/" * p * " = " * .(R2/p)), xlab=bquote(R^2 * " = " * .(R2)), ylab=expression(e^(-z^2)) ) ## at some point, soon I recommend, you should learn either lattice or ggplot. ## you might also want to look at the archives of R-SIG-Geo,start with https://www.r-project.org/mail.html ## Please Keep the list in further emails On Wed, Jan 18, 2017 at 8:09 PM, Jake William Andrae wrote: > Hi Richard, > > > If I want to use the ?plotmath function, how would I go about writing that > into the script I have for my graphs? > > I've just pasted the whole script here, with the summary label section > higlighted. Sorry to be a burden like this, I'm a real novice to R haha. > > > #Concentration > plot(Annual_precipitation, Concentration, xaxs = "i", yaxs = "i", xlim = > c(1000, 2400), ylim = c(0,500), xlab = NA, ylab = "Concentration", xaxt='n', > pch=21, bg='black', > rect(par("usr")[1],par("usr")[3],par("usr")[2],par("usr")[4],col = "gray")) > par(xpd=FALSE) > abline(lm(Concentration~Annual_precipitation)) > par(xpd=NA) > AnnualPrecipitationConcentration <- lm(Concentration~Annual_precipitation) > #Summary labels > R2 <- round(summary(AnnualPrecipitationConcentration)$r.squared, 2) > p <- anova(AnnualPrecipitationConcentration)[1,5] > if(p <= 0.001){ > p <- "< 0.001" > }else{p <- round(p, 3)} > x <- 10 > mtext(paste("R2 = ", R2), adj=0, line=1, col="black", cex=0.7) > mtext(paste("p = ", p), adj=0, line=0.1, col="black", cex=0.7) > > > Kind regards, > > Jake > > > > Jake Andrae > PhD Candidate > Geology & Geophysics � Sprigg Geobiology Centre > Department of Earth Science > School of Physical Sciences > The University of Adelaide, AUSTRALIA 5005 > Phone: 0407701565 > Email: jake.and...@adelaide.edu.au > > ________ > From: Richard M. Heiberger > Sent: Thursday, 19 January 2017 11:30:38 AM > To: Jake William Andrae > Cc: r-help@r-project.org > Subject: Re: [R] Superscript in graph text > > x <- 10 > plot(1:10, main=bquote(R^2 * "=" * .(x))) > > On Wed, Jan 18, 2017 at 8:00 PM, Richard M. Heiberger > wrote: >> ?plotmath >> >> >> plot(1:10, main=expression(R^2)) >> >> plot(1:10, main=bquote(R^2 * "=" * .(x))) >> >> On Wed, Jan 18, 2017 at 7:44 PM, Jake William Andrae >> wrote: >>> Hello, >>> >>> >>> I've added some statistical information as text to some graphs, but I'm >>> having a really hard time making the 2 in the R2 label superscript. Does >>> anyone have any suggestions? >>> >>> >>> mtext(paste("R2 = ", R2), adj=0, line=1, col="black", cex=0
[R] Superscript in graph text
Hello, I've added some statistical information as text to some graphs, but I'm having a really hard time making the 2 in the R2 label superscript. Does anyone have any suggestions? mtext(paste("R2 = ", R2), adj=0, line=1, col="black", cex=0.7) Kind regards Jake Andrae PhD Candidate Geology & Geophysics - Sprigg Geobiology Centre Department of Earth Science School of Physical Sciences The University of Adelaide, AUSTRALIA 5005 Phone: 0407701565 Email: jake.and...@adelaide.edu.au [[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] Adding regression line to each individual plot in a window with multiple plots
Hi Everyone, I've constructed a script that adds multiple plots to the plot window, but I'm having a bit of trouble adding a regression line to each individual plot. Of course, the regression lines will vary depending on the variables plotted against one another. I've attached the script. #Growing season #Construction of plots # 12 figures arranged in 3 rows and 4 columns attach(mtcars) par(mfrow=c(3,4), mar = c(.6,.5,.6,1), oma = c(15,4,2,2), xpd = NA) #Concentration plot(Growing_season_precipitation, Concentration, xaxs = "i", yaxs = "i", xlim = c(0, 700), ylim = c(0,500), xlab = NA, ylab = "Concentration", xaxt='n', pch=21, bg='black', abline(lm(Growing_season_precipitation~Concentration))) plot(Growing_season_VPD, Concentration, xaxs = "i", yaxs = "i", xlim = c(0.6, 1.8), ylim = c(0,500), xlab = NA, ylab = "", xaxt='n', pch=21, bg='black', yaxt='n') plot(Growing_season_Rhmax, Concentration, xaxs = "i", yaxs = "i", xlim = c(35, 60), ylim = c(0,500), xlab = NA, ylab = "", xaxt='n', pch=21, bg='black', yaxt='n') plot(Growing_season_temperature, Concentration, xaxs = "i", yaxs = "i", xlim = c(20,34), ylim = c(0,500), xlab = NA, ylab = "", xaxt='n', pch=21, bg='black', yaxt='n') #ACL plot(Growing_season_precipitation, ACLTotal, xaxs = "i", yaxs = "i", xlim = c(0, 700), ylim = c(28,32), xlab = "", ylab = "ACL", xaxt='n', pch=21, bg='black') plot(Growing_season_VPD, ACLTotal, xaxs = "i", yaxs = "i", xlim = c(0.6, 1.8), ylim = c(28,32), xlab = "", ylab = "", xaxt='n', pch=21, bg='black', yaxt='n') plot(Growing_season_Rhmax, ACLTotal, xaxs = "i", yaxs = "i", xlim = c(35, 60), ylim = c(28,32), xlab = "", ylab = "", xaxt='n', pch=21, bg='black', yaxt='n') plot(Growing_season_temperature, ACLTotal, xaxs = "i", yaxs = "i", xlim = c(20,34), ylim = c(28,32), xlab = "", ylab = "", xaxt='n', pch=21, bg='black', yaxt='n') #CPI plot(Growing_season_precipitation, CPITotal, xaxs = "i", yaxs = "i", xlim = c(0, 700), ylim = c(0,30), xlab = "Total precipitation (mm)", ylab = "CPI", pch=21, bg='black') plot(Growing_season_VPD, CPITotal, xaxs = "i", yaxs = "i", xlim = c(0.6, 1.8), ylim = c(0,30), xlab = "Average daily VPD (kpa)", ylab = "", pch=21, bg='black', yaxt='n') plot(Growing_season_Rhmax, CPITotal, xaxs = "i", yaxs = "i", xlim = c(35, 60), ylim = c(0,30), xlab = "Average daily RHmax (%)", ylab = "", pch=21, bg='black', yaxt='n') plot(Growing_season_temperature, CPITotal, xaxs = "i", yaxs = "i", xlim = c(20,34), ylim = c(0,30), xlab = "Average daily temperature (oC)", ylab = "", pch=21, bg='black', yaxt='n') #Plot main title title(main="Growing season (June-November, inclusive)",outer=T) Any help would be greatly appreciated! [[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] Colour gradients in ggtern
Hello, This is my first time posting to the r-help mailing list and I'm a relative amateur using R, so forgive my naivety. I am constructing a ternary diagram using the ggtern extension of the ggplot package, and I'm having some trouble with the colour gradient I want it to display. I have attached the output plot, where a rainbow colour gradient can be seen, but I really need these colours to be in reverse order. This is the command I used to construct the plot; #Plot construction > ggtern(data= C27_C29_C31, aes(x=C27,y=C29,z=C31))+geom_point(aes(colour= > GST),size=3)+theme_light()+theme_nogrid_minor()+scale_colour_gradientn(colours > = rainbow(5.5)) Is there a simple way to reverse the colours in the scale_colour_gradientn command? Kind regards, Jake Andrae __ 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.