Re: [R] GGplot controlling point size across range
On Thu, Jan 12, 2012 at 5:27 PM, Darran King darran.k...@csiro.au wrote: Hi all New to R and GGplot2 but loving the potential. I am trying to plot four separate point plots by looping over the data and plotting a different subset each time. When I plot the data as a point plot, the size of the points is determined by the data values used as below qplot(accum_rain, accum_g_radn, data = clim_sub[[i]], size = avgyld, colour = avgyld) The problem is that i want all four plots to be comparable, so a point size representing avgyld = 2000 should be the same on all four plots. However as the data for some plots has a smaller range than others and the plots are automatically scalling to the range of data in each plot, and the largest point is always assigned to the largest value a plot with a top value of say 5000 with be represented with the same size point as a plot with a top value of 7000. Any tips on how to scale the point sizes to a defined range of classes and still plot the actual data to those classes? Specify limits to scale_area: + scale_area(limits = c(0, 1000)) If you're still having problems, you might want to try the ggplot2 mailing list, as Jeff suggested. Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ __ R-help@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] GGplot controlling point size across range
Hi all New to R and GGplot2 but loving the potential. I am trying to plot four separate point plots by looping over the data and plotting a different subset each time. When I plot the data as a point plot, the size of the points is determined by the data values used as below qplot(accum_rain, accum_g_radn, data = clim_sub[[i]], size = avgyld, colour = avgyld) The problem is that i want all four plots to be comparable, so a point size representing avgyld = 2000 should be the same on all four plots. However as the data for some plots has a smaller range than others and the plots are automatically scalling to the range of data in each plot, and the largest point is always assigned to the largest value a plot with a top value of say 5000 with be represented with the same size point as a plot with a top value of 7000. Any tips on how to scale the point sizes to a defined range of classes and still plot the actual data to those classes? -- View this message in context: http://r.789695.n4.nabble.com/GGplot-controlling-point-size-across-range-tp4290858p4290858.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] GGplot controlling point size across range
A) There is a dedicated ggplot mailing list. B) proper protocol here is to provide a reproducible example including sample data that we can run. See the posting guide mentioned at the end of every message. C) create a factor (perhaps using the cut function) in your original data set, before subsetting. Use that factor to set your sizes in all your graphs. D) you might want to try using a factor that indicates which data goes in each plot and use facet wrap on your whole data set to put all the plots together. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Darran King darran.k...@csiro.au wrote: Hi all New to R and GGplot2 but loving the potential. I am trying to plot four separate point plots by looping over the data and plotting a different subset each time. When I plot the data as a point plot, the size of the points is determined by the data values used as below qplot(accum_rain, accum_g_radn, data = clim_sub[[i]], size = avgyld, colour = avgyld) The problem is that i want all four plots to be comparable, so a point size representing avgyld = 2000 should be the same on all four plots. However as the data for some plots has a smaller range than others and the plots are automatically scalling to the range of data in each plot, and the largest point is always assigned to the largest value a plot with a top value of say 5000 with be represented with the same size point as a plot with a top value of 7000. Any tips on how to scale the point sizes to a defined range of classes and still plot the actual data to those classes? -- View this message in context: http://r.789695.n4.nabble.com/GGplot-controlling-point-size-across-range-tp4290858p4290858.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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@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] ggplot - controlling point size
Can anyone illuminate the following for me? How can I get rid of the blue line in the key in the second plot? ## Create a simple data frame df=data.frame(x=1:1000, y=2*1:1000+rnorm(1000,sd=1000), type=sample(letters[1:2],1000, replace=TRUE)) ## Very nice! Almost what I want qplot(x, y, data=df, colour=factor(type)) + geom_smooth() ## Make a nicer plot, with smaller points ## but why does that add the little blue line with a 1? qplot(x, y, data=df, colour=factor(type), size=1) + geom_smooth() [[alternative HTML version deleted]] __ R-help@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.
Re: [R] ggplot - controlling point size
try this: qplot(x, y, data=df, colour=factor(type), size=I(1)) + geom_smooth() Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish Wildlife Service California, USA http://www.fws.gov/redbluff/rbdd_jsmp.aspx - Original Message From: Gene Leynes gleyne...@gmail.com To: r-help@r-project.org Sent: Tue, January 25, 2011 9:28:20 AM Subject: [R] ggplot - controlling point size Can anyone illuminate the following for me? How can I get rid of the blue line in the key in the second plot? ## Create a simple data frame df=data.frame(x=1:1000, y=2*1:1000+rnorm(1000,sd=1000), type=sample(letters[1:2],1000, replace=TRUE)) ## Very nice! Almost what I want qplot(x, y, data=df, colour=factor(type)) + geom_smooth() ## Make a nicer plot, with smaller points ## but why does that add the little blue line with a 1? qplot(x, y, data=df, colour=factor(type), size=1) + geom_smooth() [[alternative HTML version deleted]] __ R-help@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@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.
Re: [R] ggplot - controlling point size
On 1/25/2011 9:44 AM, Felipe Carrillo wrote: try this: qplot(x, y, data=df, colour=factor(type), size=I(1)) + geom_smooth() Felipe very nicely answered the how of your question. I thought I'd followup with the why. Using qplot, it assumes that you are giving a set of aesthetic mappings. As such, size is being mapped to a variable that is 1 for all entries. Then, in the usual way, a mapping is created between values of the variable in the data space and in the aesthetic space (actual sizes) and a legend is created to display this mapping. Enclosing the 1 in an I() indicates that you are giving a literal value to set the aesthetic to, in which case no mapping between aesthetic and data space (nor legend) is needed. Alternatively, you can use an identity scale to state that the data and aesthetic spaces are the same, and tell it to not plot the legend. qplot(x, y, data=df, colour=factor(type), size=1) + geom_smooth() + scale_size_identity(legend=FALSE) The distinction between aesthetic mapping and setting is even more evident in ggplot notation: ggplot(df, aes(x=x, y=y, colour=factor(type))) + geom_point(size=1) + geom_smooth() Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish Wildlife Service California, USA http://www.fws.gov/redbluff/rbdd_jsmp.aspx - Original Message From: Gene Leynesgleyne...@gmail.com To: r-help@r-project.org Sent: Tue, January 25, 2011 9:28:20 AM Subject: [R] ggplot - controlling point size Can anyone illuminate the following for me? How can I get rid of the blue line in the key in the second plot? ## Create a simple data frame df=data.frame(x=1:1000, y=2*1:1000+rnorm(1000,sd=1000), type=sample(letters[1:2],1000, replace=TRUE)) ## Very nice! Almost what I want qplot(x, y, data=df, colour=factor(type)) + geom_smooth() ## Make a nicer plot, with smaller points ## but why does that add the little blue line with a 1? qplot(x, y, data=df, colour=factor(type), size=1) + geom_smooth() -- Brian S. Diggs, PhD Senior Research Associate, Department of Surgery Oregon Health Science University __ R-help@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.
Re: [R] ggplot - controlling point size
Thank you both, very much. Using the identity function I() is a very nice trick, but it still feels like a trick. Using ggplot makes the most sense to me. ggplot(df, aes(x=x, y=y, colour=factor(type))) + geom_point(size=1) + geom_smooth() Thank you very much for taking the time to explain the syntax. I had tried using the ggplot function, but I couldn't figure out how to handle thecolour=factor(type) part. (my erroneous formulas are omitted for clarity) On Tue, Jan 25, 2011 at 12:06 PM, Brian Diggs dig...@ohsu.edu wrote: On 1/25/2011 9:44 AM, Felipe Carrillo wrote: try this: qplot(x, y, data=df, colour=factor(type), size=I(1)) + geom_smooth() Felipe very nicely answered the how of your question. I thought I'd followup with the why. Using qplot, it assumes that you are giving a set of aesthetic mappings. As such, size is being mapped to a variable that is 1 for all entries. Then, in the usual way, a mapping is created between values of the variable in the data space and in the aesthetic space (actual sizes) and a legend is created to display this mapping. Enclosing the 1 in an I() indicates that you are giving a literal value to set the aesthetic to, in which case no mapping between aesthetic and data space (nor legend) is needed. Alternatively, you can use an identity scale to state that the data and aesthetic spaces are the same, and tell it to not plot the legend. qplot(x, y, data=df, colour=factor(type), size=1) + geom_smooth() + scale_size_identity(legend=FALSE) The distinction between aesthetic mapping and setting is even more evident in ggplot notation: ggplot(df, aes(x=x, y=y, colour=factor(type))) + geom_point(size=1) + geom_smooth() Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish Wildlife Service California, USA http://www.fws.gov/redbluff/rbdd_jsmp.aspx - Original Message From: Gene Leynesgleyne...@gmail.com gleynes%...@gmail.com To: r-help@r-project.org Sent: Tue, January 25, 2011 9:28:20 AM Subject: [R] ggplot - controlling point size Can anyone illuminate the following for me? How can I get rid of the blue line in the key in the second plot? ## Create a simple data frame df=data.frame(x=1:1000, y=2*1:1000+rnorm(1000,sd=1000), type=sample(letters[1:2],1000, replace=TRUE)) ## Very nice! Almost what I want qplot(x, y, data=df, colour=factor(type)) + geom_smooth() ## Make a nicer plot, with smaller points ## but why does that add the little blue line with a 1? qplot(x, y, data=df, colour=factor(type), size=1) + geom_smooth() -- Brian S. Diggs, PhD Senior Research Associate, Department of Surgery Oregon Health Science University [[alternative HTML version deleted]] __ R-help@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.