[R] ggplot incorrect legend

John Kane jrkrideau at inbox.com
Wed Jun 6 21:02:37 CEST 2012


Try making FuelTypeNum into a factor like this:

p  <-  ggplot(data=tempTable, aes(x=Bands8, y=AvailableMWNewFormat, fill=as.factor(FuelTypeNum))) +
        geom_bar(position="stack", stat="identity")+
        coord_flip()
p

John Kane
Kingston ON Canada


> -----Original Message-----
> From: james at crosb.ie
> Sent: Wed, 6 Jun 2012 09:29:24 -0700 (PDT)
> To: r-help at r-project.org
> Subject: Re: [R] ggplot incorrect legend
> 
> Thank you for your help.
> 
> I would expect FuelTypeNum to make up the legend.  But in the legend
> there
> is an extra value of called '3' and in the chart there is an extra
> FuelTypeNum.
> 
> code:
> ggplot(data=tempTable, aes(x=Bands8, y=AvailableMWNewFormat,
> fill=FuelTypeNum)) +
>   geom_bar(position="stack", stat="identity") +
>   coord_flip()
> 
> Plot
> http://r.789695.n4.nabble.com/file/n4632552/Rplot.jpeg
> 
> Data:
> http://r.789695.n4.nabble.com/file/n4632552/dataRtest.csv dataRtest.csv
> 
> --
> View this message in context:
> http://r.789695.n4.nabble.com/ggplot-incorrect-legend-tp4632471p4632552.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 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop!



More information about the R-help mailing list