[R] ggplot2 Xlim

Wayne F wdf61 at mac.com
Thu Dec 25 23:43:45 CET 2008


I'm just a ggplot2 beginner, but...

It seems to me that you're mixing continuous and factor variables/concepts.
It looks to me as if ForkLength and Number are continuous values. But you'll
need to convert ForkLength into a factor before using geom="bar". I do that
and the graph "works" but the bars are extremely busy, which I assume is
what you mean by "crowded".

As I try several different things, I'm seeing error messages. Are you not
seeing error messages?

Is the bottom line that you simply want to display some continuous data in a
histogram-ish style, and you don't like the default "binning" of Number for
each of many ForkLengths?

If you simply use geom="line", things look clear and simple, no need to bin
or simplify or...

If you do end up using geom="bar", I believe the mistake you're making --
and I see an error message when I try -- is that you are using
scale_x_continuous whereas the X axis is discrete, so you should be using
scale_x_discrete. But then it will take some R magic to combine your "bins"
into wider bins so you get a "less crowded" look.

Or perhaps I'm misunderstanding?

   Wayne


Felipe Carrillo wrote:
> 
> Hi: I need some help.
>  I am ploting a bar graph but I can't adjust my x axis scale
>  I use this code:
>       i <-  qplot(ForkLength,Number,data=FL,geom="bar")
>     i + geom_bar(colour="blue",fill="grey65") # too crowded
> 
>      FL_dat <- ggplot(FL,aes(x=ForkLength,y=Number)) +
> geom_bar(colour="green",fill="grey65")
>     FL_dat + scale_x_continuous(limits=c(20,170)) # Can't see anything
>     
> FL	Number
> 29	22.9
> 30	63.4
> 31	199.3
> 32	629.6
> 33	2250.1
> ...
> 

-- 
View this message in context: http://www.nabble.com/ggplot2-Xlim-tp21161660p21170453.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list