Re: [R] barplot question
Hello, Ok, final retouches. 1. Divide the par() call: oldpar <- par(mar=c(9, 4.1, 4.1, 2.1)) oldfont <- par(font=3) Then, just before legend() par(oldfont) # back to normal font 2. Modify the text() call to text(as.vector(bp), y = -6.5, cex=0.7, pos = 2, offset = -0.25, ...etc... (See the meaning in the help page for text().) I think this does it. Good luck. Rui Barradas Em 31-07-2012 09:43, Michael Eisenring escreveu: Hi, thank you very much, looks awesome! I changed a few minor things. Right now I have a some last questions (i sent them also to R help) 1: I changed the font style of the plant names (along x-axis, under the bars) to "italic" . How can I avoid that the font in the legend also changes to "italic"? 2. I would like to place the plant names (along x-axis, under the bars) in a way that : a) the first plant name is under the first bar (now the first name is too much to the right). If I change the x value under "text" all names are shifted to this one x-coordinate. b)the plant names should start all on the same "height" (e.g. all exactly on y=-6.5. Now they are misplaced Any ideas? Thank you very much Michi input data (dput): structure(list(total = c(28L, 17L, 11L, 6L, 6L, 5L, 4L, 3L, 3L, 2L), young = c(29L, 22L, 15L, 8L, 5L, 3L, 2L, 2L, 2L, 2L), old = c(36L, 11L, 11L, 8L, 6L, 5L, 4L, 3L, 2L, 2L)), .Names = c("total", "young", "old"), class = "data.frame", row.names = c(NA, -10L)) R: Code plants_herbs_input_top10 <- structure(list(total = c(28L, 17L, 11L, 6L, 6L, 5L, 4L, 3L, 3L, 2L), young = c(29L, 22L, 15L, 8L, 5L, 3L, 2L, 2L, 2L, 2L), old = c(36L, 11L, 11L, 8L, 6L, 5L, 4L, 3L, 2L, 2L)), .Names = c("total", "young", "old"), class = "data.frame", row.names = c(NA, -10L)) # Keep the return value, we'll need it later # to know where to place the bars names bp <- barplot(data.matrix(plants_herbs_input_top10), width = 1, ylim = c(0,50), xaxt = "n", space = c(0.2, 1.0), ylab = "Relative frequencies (%)", beside = TRUE, col = rep(c("black", "chartreuse1", "chartreuse4"), each=10), cex.names = 0.8) par(mar=c(9, 4.1, 4.1, 2.1),font=3) #names.arg = rep(as.character(1), 3)) text(as.vector(bp),y=-6.5, cex=0.7,labels = c("Oplismenus sp.","Isachne mauritiana","Piper capense","Asplenium aethiopicum","Psychotria sp (seedlings)","Elatostema monticolum","Landolphia buchananii","Blotiella sp.","Asplenium elliottii","Hypoestes triflora","Isachne mauritiana","Oplismenus sp","Piper capense","Landolphia buchananii","Asplenium aethiopicum","Blotiella sp.","Carex chlorosaccus","Asplenium elliottii","Asplenium friesiorum","Polystichum sp.","Oplismenus sp","Psychotria sp (seedlings)","Elatostema monticolum","Asplenium aethiopicum","Hypoestes triflora","Piper capense","Asplenium elliottii","Blotiella sp.","Isoglossa substrobilina","Polystichum sp."),srt = 50,xpd = TRUE) legend.width <- max(strwidth(c("Total", "Young secondary forest","Old secondary forest"))) legend(23,54, c("Total", "Young secondary forest","Old secondary forest"), cex=1, pt.cex=1.7, pch=15, y.intersp=0.4,bty="n", text.width = legend.width/2.5, #--> legendbox : text ratio col=c("black","chartreuse1","chartreuse4")) __ 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] barplot question
Hello, Try the following. plants_herbs_input_top10 <- structure(list(total = c(28L, 17L, 11L, 6L, 6L, 5L, 4L, 3L, 3L, 2L), young = c(29L, 22L, 15L, 8L, 5L, 3L, 2L, 2L, 2L, 2L), old = c(36L, 11L, 11L, 8L, 6L, 5L, 4L, 3L, 2L, 2L)), .Names = c("total", "young", "old"), class = "data.frame", row.names = c(NA, -10L)) # Keep the return value, we'll need it later # to know where to place the bars names bp <- barplot(data.matrix(plants_herbs_input_top10), width = 1, ylim = c(0,50), xaxt = "n", space = c(0.2, 1.0), #--> this has changed ylab = "Relative frequencies (%)", beside = TRUE, col = rep(c("black", "chartreuse1", "chartreuse4"), each=10), cex.names = 0.8) #--> this has changed #--> line below commented out #names.arg = rep(as.character(1), 3)) text(as.vector(bp), y = -1, labels = rep(1:10, 3), xpd = TRUE) legend.width <- max(strwidth(c("Total", "Young secondary forest","Old secondary forest"))) legend("topright", c("Total", "Young secondary forest","Old secondary forest"), cex=0.9, pt.cex=1, pch=15, y.intersp=0.8, text.width = legend.width/2, #--> this was added col=c("black","chartreuse1","chartreuse4")) Hope this helps, Rui Barradas Em 30-07-2012 11:46, Michael Eisenring escreveu: Dear r-help members. I would like to: a) control the margin around my legend box. Unfortunately I did not find an appropriate command under "?legend". The margin around the actual legend is way too wide. There is a lot of unnecessary "empty space" on the right side. b) increase the width of the individual barplots. I saw that this can be obtained with the command "width" and "xlim".However, since I have 3 Barplots next to each other "beside=T", I could not figure it out how to do it (2 Barplots are disappearing) c) I wanted to label each bar ("names.arg") unfortunately nothing happens if I use this command (in my code i just used 1:10 for the names, in the original plot I would replace the numbers with real names) Thank you very much: Input data (dput) structure(list(total = c(28L, 17L, 11L, 6L, 6L, 5L, 4L, 3L, 3L, 2L), young = c(29L, 22L, 15L, 8L, 5L, 3L, 2L, 2L, 2L, 2L), old = c(36L, 11L, 11L, 8L, 6L, 5L, 4L, 3L, 2L, 2L)), .Names = c("total", "young", "old"), class = "data.frame", row.names = c(NA, -10L)) R-code: barplot(as.matrix(plants_herbs_input_top10),xaxt="n", space=c(0.5,12),ylab= "Relative frequencies (%)",beside=TRUE, col=c(rep("black",10),rep("chartreuse1",10),rep("chartreuse4",10)),ylim=c(0,50),cex.names=0.8,names.arg=c("1", "2", "3","4","5","6","7","8","9","10","1", "2", "3","4","5","6","7","8","9","10","1", "2", "3","4","5","6","7","8","9","10")) legend("topright",c("Total","Young secondary forest","Old secondary forest"),cex=0.9,pt.cex=1,y.intersp=0.4,pch=15,col=c("black","chartreuse1","chartreuse4")) [[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.
Re: [R] barplot question
On 07/20/2011 01:24 AM, Sally_roman wrote: In my first post is example data. Hi Sally, I was going to suggest: fish<-read.table("fish.dat",header=TRUE) controlfish<- rbind(fish$pounds[fish$net=="Control" & fish$type == "kept"], fish$pounds[fish$net=="Control" & fish$type == "discard"]) expfish<- rbind(fish$pounds[fish$net=="Experimental" & fish$type == "kept"], NA,fish$pounds[fish$net=="Experimental" & fish$type == "discard"]) barplot(controlfish,xlim=c(0,8),width=0.5,space=1.2,offset=rep(-0.5,7) barplot(expfish,width=0.5,space=1.2,add=TRUE) but the "offset" argument seems to do nothing, so this doesn't work. Jim __ 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] barplot question
People who participate in this list via email are unlikely to have your example data, or even to have any idea what you are currently referring to. Please leave enough of the previous messages in your reply to the list to provide context, and include all necessary information. Don't assume that everyone has all previous messages in a thread immediately to hand. Sarah On Tue, Jul 19, 2011 at 11:24 AM, Sally_roman wrote: > In my first post is example data. > > -- > View this message in context: > http://r.789695.n4.nabble.com/barplot-question-tp3670861p3678402.html > Sent from the R help mailing list archive at Nabble.com. Nabble.com is not the main way in which people participate in this list. -- 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] barplot question
In my first post is example data. -- View this message in context: http://r.789695.n4.nabble.com/barplot-question-tp3670861p3678402.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.
Re: [R] barplot question
As Sarah requested, could you at least read the posting guide and provide us with some sample data? -- Robert W. Baer, Ph.D. Professor of Physiology Kirksville College of Osteopathic Medicine A. T. Still University of Health Sciences 800 W. Jefferson St. Kirksville, MO 63501 660-626-2322 FAX 660-626-2965 -Original Message- From: Sally_roman Sent: Monday, July 18, 2011 12:15 PM To: r-help@r-project.org Subject: Re: [R] barplot question I would like to make stacked barplots, but with two stacked columns per x value. For cod - I have kept and discard values for 2 nets. I would like to have one stacked column for the control net with the kept and discard value and then another column with the kept and discard values for the experimental net. I can make a stacked barplots in R that will plot one net by species, but my boss would like to have both nets on the same graph. I have done it in excel, but was hoping to do the same thing in R. All of the R barplots I have found including the ones that you included as links do not demonstrate what I would like to do. Is is possible in R? -- View this message in context: http://r.789695.n4.nabble.com/barplot-question-tp3670861p3675912.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. __ 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] barplot question
I would like to make stacked barplots, but with two stacked columns per x value. For cod - I have kept and discard values for 2 nets. I would like to have one stacked column for the control net with the kept and discard value and then another column with the kept and discard values for the experimental net. I can make a stacked barplots in R that will plot one net by species, but my boss would like to have both nets on the same graph. I have done it in excel, but was hoping to do the same thing in R. All of the R barplots I have found including the ones that you included as links do not demonstrate what I would like to do. Is is possible in R? -- View this message in context: http://r.789695.n4.nabble.com/barplot-question-tp3670861p3675912.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.
Re: [R] barplot question
Hi Sally, I'm not sure what your question actually is. How to make a stacked bar plot, perhaps? If so, do any of the examples at these two sites help? http://www.harding.edu/fmccown/R/#barcharts http://addictedtor.free.fr/graphiques/search.php?engine=RGG&q=barplot If not, can you explain what you are trying to do and how? The posting guide is a good place to find out what information is needed for the list to be able to offer useful advice. Sarah On Mon, Jul 18, 2011 at 11:27 AM, Sally_roman wrote: > I have done ?barplot. I have not problems making barplots in R except for > this where there are actually two stacked columns for each fish. > I have also searched the internet to look for examples like what I would > like to plot, but have not found any which is why I thought putting a post > would be helpful. > -- 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] barplot question
I have done ?barplot. I have not problems making barplots in R except for this where there are actually two stacked columns for each fish. I have also searched the internet to look for examples like what I would like to plot, but have not found any which is why I thought putting a post would be helpful. -- View this message in context: http://r.789695.n4.nabble.com/barplot-question-tp3670861p3675588.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.
Re: [R] barplot question
Start out with ?barplot Then please tell us what your "issues" are. The barplot function is pretty flexible. If I guess that you are having difficulty simultaneously plotting one set of stacked bars and another set of non-stacked bars next to them, I would recommend two approaches. One is to play with > barplot(first_stuff) > par(new=TRUE) > barplot(second_stuff) The other, and probably better, approach, is to write your data of interest into a new matrix with some zeroes added to certain columns, and use the "beside=FALSE" argument to barplot(). Carl Sally Roman wrote: Hi - I would like to make to make a barplot of my data, but am having issues. An example of my data is: species netpair poundstype Cod Control 1 46 kept Little Skate Control 1 0 kept Summer Flounder Control 1 9 kept Windowpane Flounder Control 1 0 kept Winter Flounder Control 1 0 kept Winter Skate Control 1 0 kept Yellowtail Flounder Control 1 76 kept Cod Experimental 1 19 kept Little Skate Experimental 1 0 kept Summer Flounder Experimental 1 2 kept Windowpane Flounder Experimental 1 0 kept Winter Flounder Experimental 1 0 kept Winter Skate Experimental 1 0 kept Yellowtail Flounder Experimental 1 9 kept Cod Control 1 14 discard Little Skate Control 1 75 discard Summer Flounder Control 1 1 discard Windowpane Flounder Control 1 32 discard Winter Flounder Control 1 16 discard Winter Skate Control 1 225 discard Yellowtail Flounder Control 1 7 discard Cod Experimental 1 7 discard Little Skate Experimental 1 64 discard Summer Flounder Experimental 1 3 discard Windowpane Flounder Experimental 1 26 discard Winter Flounder Experimental 1 12 discard Winter Skate Experimental 1 136 discard Yellowtail Flounder Experimental 1 5 discard I have 9 total pairs. I would like to be able be able to make a barplot by pair that shows the catch of the control net (kept & discard) stacked with the catch of the experimental net also stacked by species like the image below I did in excel. http://r.789695.n4.nabble.com/file/n3670861/image.jpg I can make barplots by net and pair, but I would like to have both nets on one barplot if possible. -- - Sent from my Cray XK6 __ 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.