I would like to have a plot with values in a reversed order (as shown in fig 2). I tried to plot the graph in R using the following codes plot(density,depth,pch=as.numeric(species),xlab="fish density (#/m2)",ylab="water depth (m)") legend(locator(n=1),legend=c("Tropheus brichardi","Petrochromis kazumbe"),pch=1:2) unfortunately I can not reverse the axis to get a plot like the one shown in fig.2 Please can you help me with the codes? Thanks you Renny [[alternative HTML version deleted]]
R-help strips attachments so your post has three problems: 1. No plot to look at 2. No data to replicate your code 3. Email is in html format instead of plain text Try again using plain text mail, copy the results of dput(your.data.frame) into your email and provide code that generates the figure and then tell us how it should be different. It is likely that the solution is simple, eg set.seed(42) depth <- runif(10)*10 density <- rnorm(10, 5) plot(density, depth) # normal plot(density, depth, ylim=c(10, 0)) # reversed ------------------------------------- David L Carlson Department of Anthropology Texas A&M University College Station, TX 77840-4352 -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Renalda Munubi-Misinzo Sent: Friday, March 14, 2014 2:55 AM To: r-help at r-project.org Subject: [R] plots I would like to have a plot with values in a reversed order (as shown in fig 2). I tried to plot the graph in R using the following codes plot(density,depth,pch=as.numeric(species),xlab="fish density (#/m2)",ylab="water depth (m)") legend(locator(n=1),legend=c("Tropheus brichardi","Petrochromis kazumbe"),pch=1:2) unfortunately I can not reverse the axis to get a plot like the one shown in fig.2 Please can you help me with the codes? Thanks you Renny [[alternative HTML version deleted]] ______________________________________________ R-help at 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.
On 03/14/2014 06:55 PM, Renalda Munubi-Misinzo wrote:> I would like to have a plot with values in a reversed order (as shown in > fig 2). I tried to plot the graph in R using the following codes > > plot(density,depth,pch=as.numeric(species),xlab="fish density > (#/m2)",ylab="water depth (m)") > > legend(locator(n=1),legend=c("Tropheus brichardi","Petrochromis > kazumbe"),pch=1:2) > unfortunately I can not reverse the axis to get a plot like the one shown > in fig.2 Please can you help me with the codes? >Hi Renny, Your image did not make it through to the list, but if David's suggestion isn't what you want, have a look at the rev.axis function in the plotrix package. Jim
Renalda - your figure got stripped out. I'll assume you mean to have depth on the vertical axis with a zero at the top and increasing (+) depth as you go down. This is pretty simple to do. 1) use the (-) of depth on the y-axis 2) make the plot without the y-axis labels (yaxt='n') using ylim=c(-(max(depth)),0) 3) add back an axis using the levels you want and (-) values axis(2,at=c(what you want, negative),labels=c(what you want, positive)) voila e.g. depth <- 1:10 density <- 2:11 plot(density,-depth,ylim=-rev(range(depth)),yaxt='n') axis(2,-c(0,2,4,6,8,10),labels=c(0,2,4,6,8,10) )# if you want labels at 0,2,4,6,8,10 David Stevens Good luck On 3/14/2014 1:55 AM, Renalda Munubi-Misinzo wrote:> I would like to have a plot with values in a reversed order (as shown in > fig 2). I tried to plot the graph in R using the following codes > > plot(density,depth,pch=as.numeric(species),xlab="fish density > (#/m2)",ylab="water depth (m)") > > legend(locator(n=1),legend=c("Tropheus brichardi","Petrochromis > kazumbe"),pch=1:2) > unfortunately I can not reverse the axis to get a plot like the one shown > in fig.2 Please can you help me with the codes? > > Thanks you > Renny > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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.-- David K Stevens, P.E., Ph.D. Professor and Head, Environmental Engineering Civil and Environmental Engineering Utah Water Research Laboratory 8200 Old Main Hill Logan, UT 84322-8200 435 797 3229 - voice 435 797 1363 - fax david.stevens at usu.edu