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
34 7452.5
35 19352.9
36 17655.5
37 13020.6
38 5856.0
39 2039.4
40 1261.2
41 780.2
42 826.6
43 739.0
44 608.2
45 694.3
46 599.5
47 690.4
48 762.9
49 594.6
50 771.7
51 695.3
52 784.5
53 780.1
54 823.6
55 883.2
56 747.6
57 834.4
58 716.7
59 632.8
60 670.4
61 511.0
62 577.4
63 538.0
64 452.3
65 451.7
66 355.7
67 294.1
68 278.8
69 165.5
70 208.7
71 161.6
72 159.9
73 100.9
74 84.4
75 110.3
76 69.3
77 60.7
78 63.2
79 28.8
80 46.1
81 34.6
82 37.1
83 35.5
84 35.7
85 24.3
86 17.5
87 24.9
88 21.5
89 17.4
90 14.0
91 7.8
92 10.1
93 6.8
94 2.9
95 4.0
96 7.3
97 4.6
98 4.0
99 1.7
100 5.0
101 11.3
102 3.0
103 5.2
104 9.4
105 6.4
106 1.0
107 8.5
108 8.6
109 10.1
110 9.0
111 11.7
112 16.0
113 3.1
114 7.6
115 3.9
116 7.0
117 6.9
118 8.1
119 2.0
121 3.7
122 1.9
123 4.0
124 6.3
126 2.0
127 2.0
128 1.0
129 2.0
132 2.0
134 7.3
135 1.0
136 1.0
139 1.0
142 1.0
145 1.0
152 2.0
161 2.5
172 1.0
Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish & Wildlife Service
California, USA
ggplot2 Xlim
6 messages · Felipe Carrillo, stephen sefick, Wayne F +1 more
would you make this reproducible, please. Think cut and paste out of email into R. ?dput my guess would be the breaks argument On Wed, Dec 24, 2008 at 12:31 PM, Felipe Carrillo
<mazatlanmexico at yahoo.com> 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
34 7452.5
35 19352.9
36 17655.5
37 13020.6
38 5856.0
39 2039.4
40 1261.2
41 780.2
42 826.6
43 739.0
44 608.2
45 694.3
46 599.5
47 690.4
48 762.9
49 594.6
50 771.7
51 695.3
52 784.5
53 780.1
54 823.6
55 883.2
56 747.6
57 834.4
58 716.7
59 632.8
60 670.4
61 511.0
62 577.4
63 538.0
64 452.3
65 451.7
66 355.7
67 294.1
68 278.8
69 165.5
70 208.7
71 161.6
72 159.9
73 100.9
74 84.4
75 110.3
76 69.3
77 60.7
78 63.2
79 28.8
80 46.1
81 34.6
82 37.1
83 35.5
84 35.7
85 24.3
86 17.5
87 24.9
88 21.5
89 17.4
90 14.0
91 7.8
92 10.1
93 6.8
94 2.9
95 4.0
96 7.3
97 4.6
98 4.0
99 1.7
100 5.0
101 11.3
102 3.0
103 5.2
104 9.4
105 6.4
106 1.0
107 8.5
108 8.6
109 10.1
110 9.0
111 11.7
112 16.0
113 3.1
114 7.6
115 3.9
116 7.0
117 6.9
118 8.1
119 2.0
121 3.7
122 1.9
123 4.0
124 6.3
126 2.0
127 2.0
128 1.0
129 2.0
132 2.0
134 7.3
135 1.0
136 1.0
139 1.0
142 1.0
145 1.0
152 2.0
161 2.5
172 1.0
Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish & Wildlife Service
California, USA
______________________________________________ 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.
Stephen Sefick Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis
1 day later
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.
Wayne: What's crowded are my x axis labels. The bars look fine on my graph but the labels are being displayed from 29 to 170 one by one. I need something like a seq(29,170 by:10) or something like that. I don't want to treat my FL as factor because I don't want a bar per each FL value, I only want to count the number of FL at any given FL size. Thanks
--- On Thu, 12/25/08, Wayne F <wdf61 at mac.com> wrote:
From: Wayne F <wdf61 at mac.com> Subject: Re: [R] ggplot2 Xlim To: r-help at r-project.org Date: Thursday, December 25, 2008, 2:43 PM 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.
______________________________________________ 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.
Hi Felipe, It sounds like ForkLength is a factor - what deos str(FL) tell you? You might also need geom_bar(..., stat = "identity") since your data are pretabulated. Hadley On Fri, Dec 26, 2008 at 2:44 PM, Felipe Carrillo
<mazatlanmexico at yahoo.com> wrote:
Wayne: What's crowded are my x axis labels. The bars look fine on my graph but the labels are being displayed from 29 to 170 one by one. I need something like a seq(29,170 by:10) or something like that. I don't want to treat my FL as factor because I don't want a bar per each FL value, I only want to count the number of FL at any given FL size. Thanks --- On Thu, 12/25/08, Wayne F <wdf61 at mac.com> wrote:
From: Wayne F <wdf61 at mac.com> Subject: Re: [R] ggplot2 Xlim To: r-help at r-project.org Date: Thursday, December 25, 2008, 2:43 PM 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.
______________________________________________ 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.
______________________________________________ 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.
Thanks Hadley: I had already gone to your website and stat="identity" is what I needed.
--- On Fri, 12/26/08, hadley wickham <h.wickham at gmail.com> wrote:
From: hadley wickham <h.wickham at gmail.com> Subject: Re: [R] ggplot2 Xlim To: mazatlanmexico at yahoo.com Cc: r-help at r-project.org, "Wayne F" <wdf61 at mac.com> Date: Friday, December 26, 2008, 3:31 PM Hi Felipe, It sounds like ForkLength is a factor - what deos str(FL) tell you? You might also need geom_bar(..., stat = "identity") since your data are pretabulated. Hadley On Fri, Dec 26, 2008 at 2:44 PM, Felipe Carrillo <mazatlanmexico at yahoo.com> wrote:
Wayne: What's crowded are my x axis labels. The bars look
fine on my graph but the labels are being displayed from 29 to 170 one by one. I need something like a seq(29,170 by:10) or something like that. I don't want to treat my FL as factor because I don't want a bar per each FL value, I only want to count the number of FL at any given FL size. Thanks
--- On Thu, 12/25/08, Wayne F <wdf61 at mac.com>
wrote:
From: Wayne F <wdf61 at mac.com> Subject: Re: [R] ggplot2 Xlim To: r-help at r-project.org Date: Thursday, December 25, 2008, 2:43 PM 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:
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.
______________________________________________ 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. -- http://had.co.nz/