[R] How to decrease size of points?
Avi Gross
@v|gro@@ @end|ng |rom ver|zon@net
Wed Sep 30 21:59:22 CEST 2020
It is better to understand the requirements before suggesting a way to do it.
My GUESS is that the questioner wants the circles of different sizes based on a factor but the natural choices start too high for their needs/taste. So they want a base size of 0.8 that is either the minimum or maximum size. I offer a verbal solution but end with possibly a simple solution using other functionality.
So I am proposing a solution but only if the above is what you want. If it is something else, state it clearly.
So say you want the sizes to go from 0.8 to 1.2. The approach offered can be tweaked to do the following in English.
Calculate the number of unique levels of the factor in the data. Make sure the factor is (re)ordered to have those N levels and in the right order.
Create a vector of N values but they should not all be 0.8. They should have the first one be 0.8, and the second would have added to that something like (1.2 - 0.8)/N and the next has double that added and so on. With the proper calculations, you get a smoothly increasing value for a size for the circles in a vector of the right size. Many other methods can be used like multiplying the preceding size by 1.1 and you can play rounding games or anything else. In the end, you have a_vector looking a bit like c(0.8, 0.84, 0.88, 0.92, ... 1.16, 1.20) or whatever.
Now note the word "manual" in scale_size_manual(values = a_vector)
It means you are doing things manually rather than allowing ggplot to choose them automatically. Saying size=variable is now not useful or even wanted. You are choosing manually.
Just give it the vector of increasing sizes you wanted and it should use them in that order as long as the factor you use is in the order you want. If it is a categorical variable with your required order, there are ways to get what you want either by making it ordered or re-ordering the factors so the hidden index values of 1,2,3 ... correspond.
I have not tried this and am not supplying actual code, just the concept. But this approach feels too long and cumbersome given how common a need like the one I think you want might be.
A much better solution would be a way to specify a baseline minimum and perhaps maximum and let the underlying ggplot print method figure things out. If the manual pages are correct, it may make sense to use other "scale" functions that allow you to specify a minimum and maximum size
https://www.rdocumentation.org/packages/ggplot2/versions/1.0.1/topics/scale_size
scale_size_continuous(..., range = c(1, 6))
scale_size(..., range = c(1, 6))
scale_size_discrete(..., range = c(1, 6))
I see examples that suggest it works the way I want:
(p <- qplot(mpg, cyl, data=mtcars, size=cyl))
...
p + scale_size(range = c(0, 10))
p + scale_size(range = c(1, 2))
In the above you both ask ggplot to adjust the size to match the variable/column called cylinder and also provide a range for those values to be distributed between.
Sounds like a plan to try?
-----Original Message-----
From: R-help <r-help-bounces using r-project.org> On Behalf Of Medic
Sent: Wednesday, September 30, 2020 3:01 PM
To: Rui Barradas <ruipbarradas using sapo.pt>; r-help using r-project.org
Subject: Re: [R] How to decrease size of points?
№1 Medic:
The code works as I want, but the points (circles) on the plot are too big. How to decrease them? Where to insert (for instance) size = 0.8 for points (circles) on plot?
p1 <- p + geom_point(aes(size = Stage), alpha = 1/3) + xlab ("X") +
ylab("Y") + geom_smooth()
Stage is factor, x and y - continuous
===
№2 Rui Barradas:
add the scale_size
p1 + scale_size_manual(values = 0.8)
===
№3 Medic:
Thanks Rui, but I got:
Error: Insufficient values in manual scale. 12 needed but only 1 provided.
(or Error: Continuous value supplied to discrete scale) ===
№4 Rui Barradas:
Try
nsize <- length(unique(df1$Stage))
before the plot and then
p1 + scale_size_manual(values = rep(0.8, nsize)) ===
№5 Medic:
Rui, your example is very good!
Now your code works, but not as I want.
Why did I use:
geom_point(aes(size = Stage)...?
In order to receive points of DIFFERENT size!
And what does your code do?
It assigns the same fixed size to ALL points.
I don't need this.
I sincerely thank you and closing the topic!
______________________________________________
R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
More information about the R-help
mailing list