[R] ggplot - controlling point size
diggsb at ohsu.edu
Tue Jan 25 19:06:15 CET 2011
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)
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) +
The distinction between aesthetic mapping and setting is even more
evident in ggplot notation:
ggplot(df, aes(x=x, y=y, colour=factor(type))) +
> Felipe D. Carrillo
> Supervisory Fishery Biologist
> Department of the Interior
> US Fish& Wildlife Service
> California, USA
> ----- Original Message ----
>> From: Gene Leynes<gleynes+r at gmail.com>
>> To: r-help at 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
More information about the R-help