Hi there everyone! So I'm a student in college, taking a very basic Statistics course. We're using R for most of our assignments. I've hit a pretty big wall here. I'm attempting to create a heat map of the entire united states which corresponds to a set of percentages I have for each state. My teacher suggested that I simply create a color palette with RColorBrewer that is in the exact order of the states by alphabet so that I can simply plug that pallette into the maps package and have it fill alphabetically with the gradient I created through my list. My problem is that I can't seem to create my own color palette using the color codes. How do i create a color palette using a list of color codes? For example #41BH39 so on and so forth. Is this clear? Please ask me to clarify if it isn't. Thanks! -- View this message in context: http://r.789695.n4.nabble.com/RColorBrewer-tp4646790.html Sent from the R help mailing list archive at Nabble.com.
Yakamu Yakamu
2012-Oct-19 19:22 UTC
[R] how can I make a legend that applies for all the barplots in one same page?
Dear all, I would like to make 6 barplots in one page but with a legend that applies to all the barplots and would like to put it in the central-bottom of the page. I know only how to make legend for individual barplot, but since all my barplots have the same type and would be better if i just use one legend for all of them, and i cannot seem to find a way to put the legend in the bottom and centered. Please advice... I set the margins (and font type) as follows : par(mfrow=c(3,2),pty="m") # Layout with 3x2 plots par(oma=c(3,4,3,4)) # Outer margins par(mar=c(5,5,2,2)) # Inner margins par(xpd=F) par(family="serif", font=1) # Times New Roman font ANy great help is kindly appreciated, cheers, Yayu [[alternative HTML version deleted]]
Greg Snow
2012-Oct-19 19:50 UTC
[R] how can I make a legend that applies for all the barplots in one same page?
First of all, in the command par(xpd=F), what is the value of F? If it is the default value of FALSE then that says to not plot anything outside of the plot region, so any attempts to put a legend in the outer margin will not plot anything. if F is TRUE (which is a recipe for disaster) then you can put things into the figure region (inner margins) but it will still not plot in the outer regions. Only if F is NA will it allow plotting in the outer margin. That is why it is best practice not to use F and T, but to spell out the logical names. Best for this case is par(xpd=NA). Now you can plot in the outer margins. Use the grconvertX and grconvertY functions to find the location to put the legend, then use the legend function to plot it. On Fri, Oct 19, 2012 at 1:22 PM, Yakamu Yakamu <iam_yakamu at yahoo.com> wrote:> Dear all, > I would like to make 6 barplots in one page but with a legend that applies to all the barplots and would like to put it in the central-bottom of the page. > > I know only how to make legend for individual barplot, but since all my barplots have the same type and would be better if i just use one legend for all of them, and i cannot seem to find a way to put the legend in the bottom and centered. > Please advice... > I set the margins (and font type) as follows : > > par(mfrow=c(3,2),pty="m") # Layout with 3x2 plots > par(oma=c(3,4,3,4)) # Outer margins > par(mar=c(5,5,2,2)) # Inner margins > par(xpd=F) > par(family="serif", font=1) # Times New Roman font > > ANy great help is kindly appreciated, > cheers, > Yayu > > [[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. >-- Gregory (Greg) L. Snow Ph.D. 538280 at gmail.com
Jim Lemon
2012-Oct-20 09:33 UTC
[R] how can I make a legend that applies for all the barplots in one same page?
On 10/20/2012 06:22 AM, Yakamu Yakamu wrote:> Dear all, > I would like to make 6 barplots in one page but with a legend that applies to all the barplots and would like to put it in the central-bottom of the page. > > I know only how to make legend for individual barplot, but since all my barplots have the same type and would be better if i just use one legend for all of them, and i cannot seem to find a way to put the legend in the bottom and centered. > Please advice... > I set the margins (and font type) as follows : > > par(mfrow=c(3,2),pty="m") # Layout with 3x2 plots > par(oma=c(3,4,3,4)) # Outer margins > par(mar=c(5,5,2,2)) # Inner margins > par(xpd=F) > par(family="serif", font=1) # Times New Roman font >Hi Yayu, First, leave enough space below your plots, then: # allow the legend to display outside the plots par(xpd=TRUE) # work out where you want the legend in the user coordinates # of the _last_ plot displayed legend(x,y,...) par(xpd=FALSE) Jim
Prof Brian Ripley
2012-Oct-20 09:40 UTC
[R] how can I make a legend that applies for all the barplots in one same page?
On 20/10/2012 10:33, Jim Lemon wrote:> On 10/20/2012 06:22 AM, Yakamu Yakamu wrote: >> Dear all, >> I would like to make 6 barplots in one page but with a legend that >> applies to all the barplots and would like to put it in the >> central-bottom of the page. >> >> I know only how to make legend for individual barplot, but since all >> my barplots have the same type and would be better if i just use one >> legend for all of them, and i cannot seem to find a way to put the >> legend in the bottom and centered. >> Please advice... >> I set the margins (and font type) as follows : >> >> par(mfrow=c(3,2),pty="m") # Layout with 3x2 plots >> par(oma=c(3,4,3,4)) # Outer margins >> par(mar=c(5,5,2,2)) # Inner margins >> par(xpd=F) >> par(family="serif", font=1) # Times New Roman font >> > Hi Yayu, > First, leave enough space below your plots, then: > > # allow the legend to display outside the plots > par(xpd=TRUE) > # work out where you want the legend in the user coordinates > # of the _last_ plot displayed > legend(x,y,...) > par(xpd=FALSE)It is clearer and safer to use legend(x,y, ..., xpd = TRUE) See the help page.> > Jim > > ______________________________________________ > 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.-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
This is perilously close to a straightforward homework question which is not usually answwered here but you get brownie points for saying you are a student. Also you did not follow the posting guidelines so we have no idea what are doing, what package(s) you may be using etc. Have a look at http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example for some idea of how to ask the question. That said, just try googling for something like "RColorBrewer create personal palate" and see where it leads. The first one I found was: http://wiki.stdout.org/rcookbook/Graphs/Colors%20%28ggplot2%29/ whhich may be of use if you are using ggplot2, or perhaps even if you are not. John Kane Kingston ON Canada> -----Original Message----- > From: abrutvan at bennington.edu > Sent: Fri, 19 Oct 2012 11:50:26 -0700 (PDT) > To: r-help at r-project.org > Subject: [R] RColorBrewer > > Hi there everyone! So I'm a student in college, taking a very basic > Statistics course. We're using R for most of our assignments. I've hit a > pretty big wall here. I'm attempting to create a heat map of the entire > united states which corresponds to a set of percentages I have for each > state. My teacher suggested that I simply create a color palette with > RColorBrewer that is in the exact order of the states by alphabet so that > I > can simply plug that pallette into the maps package and have it fill > alphabetically with the gradient I created through my list. My problem is > that I can't seem to create my own color palette using the color codes. > How > do i create a color palette using a list of color codes? For example > #41BH39 > so on and so forth. Is this clear? Please ask me to clarify if it isn't. > > Thanks! > > > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/RColorBrewer-tp4646790.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.____________________________________________________________ FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family! Visit http://www.inbox.com/photosharing to find out more!