Make “Solar System” Plots With {ggsolar}
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
I was cranking out a blog post for work earlier this week that shows off just how many integrations our platform has. I won’t blather about that content here, but as I was working on it, I really wanted to show off all the integrations.
A table seemed far too boring.
Several categorized unordered lists seemed too unwieldy.
Then, it dawned on me that I could make a visual representation of all the integration partners we have by thinking of the entire integrations’ ecosystem as a “universe” with each category being a “solar system” of that universe.
I’ve been leaning more heavily on javsascript for datavis these days, but I will always be more comfortable in {ggplot2}, so I headed to R to design a way to:
- generate concentric orbits for “n” solar systems
- randomize the placement of the planets in each ring
- make a decent plot!
I worked with one of the most amazing designers on the planet (heh) to come up with some stellar (heh) styling for it, and this was the result:
I took the styling guidance and wrapped the messy, individual functions I had into a new {ggsolar} package, you can find at https://github.com/hrbrmstr/ggsolar.
It’s pretty raw, and I need to “geomify” it at some point, but it has
- a function to generate the concentric circle polygons
- another one to identify a random point on each ring
- a naive plotting function, and
- a theme cleanup function for decent output.
The default is to generate uniformly distributed concentric circles, but you have the option of supplying a custom radii vector to make it more “real”/“solar-sysetm-y”.
Here’s the general flow:
# sol_planets is a built in vector of our system's planet names sol_orbits <- generate_orbits(sol_planets) set.seed(1323) # this produced a decent placements # naive but it works! You can specify your own point picker, too. placed_planets <- randomize_planet_positions(sol_orbits) # do the thing! plot_orbits( orbits = sol_orbits, planet_positions = placed_planets, label_planets = TRUE, label_family = hrbrthemes::font_es_bold ) + hrbrthemes::theme_ipsum_es(grid="") + coord_equal() + labs( title = "Sol", caption = "Pluto is 100% a planet" ) + theme_enhance_solar()
Random Systems
I included a generate_random_planets()
function that uses a hidden Markov model to create believable planetary names, so you can now make your own universe with {ggplot2}!
set.seed(42) (rando_planets <- generate_random_planets(12)) rando_orbits <- generate_orbits(rando_planets) set.seed(123) # this produced decent placements placed_planets <- randomize_planet_positions(rando_orbits) plot_orbits( orbits = rando_orbits, planet_positions = placed_planets, label_planets = TRUE, label_family = hrbrthemes::font_es_bold ) + hrbrthemes::theme_ipsum_es(grid="") + coord_equal() + labs( title = "Rando System" ) + theme_enhance_solar()
FIN
Kick the tyres, use {gganimate} to make some animations, and be the ruler of your own universe! (We’re going to try to generate team “org charts” with these later in the week, so be creative, too!).
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.