![]() ![]() Here’s how to generate a histogram from the Palmer penguins data set with ggblanket, (example taken from the package website): library(ggblanket) library(palmerpenguins) penguins |> gg_histogram(x = body_mass_g, col = species) Sharon Machlis ggblanket may not make it easier for me to remember all those options, but they are easier to find. And that means I only need to look at one help file to see things like pal is for defining a color palette and y_title sets the y-axis title, instead of searching help files for multiple separate functions. One of my favorite things about the package is that it merges col and fill aesthetics into a single col aesthetic, so I no longer need to remember whether to use a scale_fill_ or scale_colour_ function.Īnother ggblanket benefit: Its geoms such as gg_col() or gg_point() include customization options within the functions themselves instead of requiring separate layers. If you tend to forget which geoms to use for what, I recommend giving ggblanket a try. Several packages aim to streamline ggplot2 so common data visualizations are either simpler or more intuitive. Ggplot2 is incredibly powerful and customizable, but sometimes that comes at a cost of complexity. Easier ggplot2 code: ggblanket and others Ggpackets is by Doug Kelkhoff and is available on CRAN. Graph created with a custom ggpackets geom. Ggplot(snowfall2000s, aes(x = Winter, y = Total)) + my_geom_col() Sharon Machlis Here’s how simple it is to use that new geom: Note that I saved everything except the original graph’s first ggplot() line of code to the custom geom. Here’s how to turn that into a custom geom called my_geom_col: library(ggpackets) my_geom_col <- ggpacket() + geom_col(color = "black", fill="#0072B2") + theme_minimal() + theme(panel.border = element_blank(), = element_blank(), = element_blank(), axis.line = element_line(colour = "gray"), plot.title = element_text(hjust = 0.5), plot.subtitle = element_text(hjust = 0.5) ) + ylab("") + xlab("") The first code block is the initial graph: library(ggplot2) library(scales) library(rio) snowfall2000s <- import("") ggplot(snowfall2000s, aes(x = Winter, y = Total)) + geom_col(color = "black", fill="#0072B2") + theme_minimal() + theme(panel.border = element_blank(), = element_blank(), = element_blank(), axis.line = element_line(colour = "gray"), plot.title = element_text(hjust = 0.5), plot.subtitle = element_text(hjust = 0.5) ) + ylab("") + xlab("") The example code below creates a bar chart from Boston snowfall data, and it has several lines of customizations that I’d like to use again with other data.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |