[R] How to remove legend?

ONKELINX, Thierry Thierry.ONKELINX at inbo.be
Mon Oct 8 15:01:33 CEST 2007


Hi Christophe,

Although I'm a fan of ggplot2, it's lack of documentation is a drawback.
I was having a similar problem and Hadley suggested the "sc$legend <-
FALSE" solution. AFAIK it isn't documented (yet). Have a look at
Hadley's website and the archive of this list for more documentation.

This code adds a solid border to to bars. But I can't figure out how to
add the main title to the plot (using ggplot instead of qplot). 

library(ggplot2)
dow <- data.frame(dayofweek = factor(1:7), p = runif(7), w = c(0, 1, 1,
1, 1, 1, 0))
sc <- scale_fill_continuous()
sc$legend <- FALSE
ggplot(data = dow, aes(x = dayofweek, y = p, fill = w), "t") +
scale_x_discrete("Day") + scale_y_continuous("Arrival Rate") +
geom_bar(colour = "black") + sc

Cheers,

Thierry


------------------------------------------------------------------------
----
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium
tel. + 32 54/436 185
Thierry.Onkelinx op inbo.be
www.inbo.be 

Do not put your faith in what statistics say until you have carefully
considered what they do not say.  ~William W. Watt
A statistical analysis, properly conducted, is a delicate dissection of
uncertainties, a surgery of suppositions. ~M.J.Moroney



> -----Oorspronkelijk bericht-----
> Van: Christoph Krammer [mailto:ck op altaica.de] 
> Verzonden: maandag 8 oktober 2007 14:35
> Aan: ONKELINX, Thierry; r-help op r-project.org
> Onderwerp: RE: [R] How to remove legend?
> 
> Hello Thierry,
> 
> thanks for your fast response.
> 
> This does what I want, thank you.
> 
> Where can I get more documentation for this 
> scale_fill_continuous() method and similar ones? I figured 
> out how to choose the colors but I don't quite get how to add 
> a solid border to the bars.
> 
> Regards,
> Christoph 
> 
> -----Original Message-----
> From: ONKELINX, Thierry [mailto:Thierry.ONKELINX op inbo.be]
> Sent: Monday, October 08, 2007 1:47 PM
> To: Christoph Krammer; r-help op r-project.org
> Subject: RE: [R] How to remove legend?
> 
> Try somelike this
> 
> library(ggplot2)
> dow <- data.frame(dayofweek = factor(1:7), p = runif(7), w = 
> c(0, 1, 1, 1, 1, 1, 0)) sc <- scale_fill_continuous() 
> sc$legend <- FALSE qplot(dayofweek, p, data=dow, geom="bar", 
> xlab="Day", ylab="Arrival Rate", main="Spam by Weekday", fill=w) + sc
> 
> HTH,
> 
> Thierry
> 
> --------------------------------------------------------------
> ----------
> ----
> ir. Thierry Onkelinx
> Instituut voor natuur- en bosonderzoek / Research Institute 
> for Nature and Forest Cel biometrie, methodologie en 
> kwaliteitszorg / Section biometrics, methodology and quality 
> assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 
> 54/436 185 Thierry.Onkelinx op inbo.be www.inbo.be 
> 
> Do not put your faith in what statistics say until you have 
> carefully considered what they do not say.  ~William W. Watt 
> A statistical analysis, properly conducted, is a delicate 
> dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney
> 
>  
> 
> > -----Oorspronkelijk bericht-----
> > Van: r-help-bounces op r-project.org
> > [mailto:r-help-bounces op r-project.org] Namens Christoph Krammer
> > Verzonden: maandag 8 oktober 2007 13:35
> > Aan: r-help op r-project.org
> > Onderwerp: [R] How to remove legend?
> > 
> > Hello,
> > 
> > I want to do some simple bar plots on email arrival data, 
> but I do not 
> > quite get the point how to remove the legend. I use the following 
> > code:
> > 
> > > dow <-
> > 
> read.csv(file="j:/uni_lernen/da_stockspam/svn/data/c411_weekday.txt",
> > header=TRUE)
> > > dow$dayofweek <- factor(dow$dayofweek) days <- c("Sun",
> > "Mon", "Tue",
> > > "Wed","Thu", "Fri", "Sat")
> > > levels(dow$dayofweek) <- days
> > > dow
> >   dayofweek     c      p w
> > 1       Sun 16477 0.1333 0
> > 2       Mon 19384 0.1568 1
> > 3       Tue 18638 0.1507 1
> > 4       Wed 19747 0.1597 1
> > 5       Thu 20709 0.1675 1
> > 6       Fri 16412 0.1327 1
> > 7       Sat 12283 0.0993 0
> > 
> > > qplot(dayofweek, p, data=dow, geom="bar", xlab="Day", 
> ylab="Arrival 
> > > Rate",
> > main="Spam by Weekday", fill=w)
> > 
> > The idea of the w parameter is to give weekends a different 
> color. But 
> > when I do this, I always get a legend of "w" with two 
> entries for its 
> > two colors.
> > 
> > How can I avoid this?
> > 
> > Thanks and regards,
> >  Christoph
> > 
> > ______________________________________________
> > R-help op 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.
> > 
> 
> 



More information about the R-help mailing list