Plotting many circles with different radii

69 views
Skip to first unread message

Sara Williams

unread,
Jul 25, 2016, 3:46:51 PM7/25/16
to ggplot2
Hello group,

I'm interested in plotting many circles (45k) all with centers at (0,0) and each with a different radius. This seems basic enough but I've had a real bear of a time getting a plot to work and I cannot find a help post that would allow me to be able to do this. However, my reading leads me to think that geom_point with scale_radius or scale_size is my best bet. Still, I have been unable to produce a plot that has accurate circle sizes according to my radius scale.

Basically, I am plotting animal movement step length (across all possible angles of the circle) and have used models and simulation to obtain 45k steps - these will equal the radii of my circles. Using a transparency value, I'd like to indicate the step lengths that have a higher probability of being simulated (there will be many more circles with smaller radii and resultantly the plot will be darker in the center and lighter toward the edges).

Example data:

z <- seq(0, 10000, length.out = 45000) # radii (step lengths)
x <- rep(0, length(z)) # x center for each circle
y <- rep(0, length(z)) # y center for each circle
points <- data.frame(x, y, z)
points <- dplyr::arrange(points, by = z)

p  <- ggplot(points) + 
        geom_point(aes(x, y, size = z), colour = "darkred", alpha = 0.05) +
        scale_radius(range = c(0, 10000), guide = FALSE)

Any thoughts or insight on how to ensure that the radii of the points are in fact aligned with the radii I have in my data frame would be greatly appreciated. Or any different approaches to plotting concentric circles with varying radii would be quite helpful as well.

Thanks a lot,
Sara 

Hadley Wickham

unread,
Jul 26, 2016, 4:03:32 PM7/26/16
to Sara Williams, ggplot2
I think the key is to use scale_size_identity().

And you'll probably need to read
https://cran.r-project.org/web/packages/ggplot2/vignettes/ggplot2-specs.html
to get the details exactly right.

Hadley
> --
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example:
> https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ggplot2" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ggplot2+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
http://hadley.nz
Reply all
Reply to author
Forward
0 new messages