![]() Assuming we have a starting and stopping point set already by the data we’re plotting, we can think of properties of a line that are purely aesthetic: color, thickness, and what type of line it is (solid, dotted, dashed, etc). One of the most fundamental concepts in a plot is a line. They ensure that labels don’t overlap (removing some if necessary), and then make sure they don’t spill off over the edges of the plot. ![]() I recently learned about these from Hadley Wichkham’s book-in-progress, ggplot2 (version 3) which you can view here. Note that within facet_wrap, I’ve added a couple extra arguments ( check_overlap, vjust, and hjust). cereal <- read.csv("")Ĭereal$mfr <- forcats::fct_recode(cereal$mfr,Ĭ <- ggplot(cereal, aes(fiber, rating)) +Ĭheck_overlap = TRUE, vjust = "inward", hjust = "inward") + We’ll load it in, make a few changes as before, and make a faceted plot showing the amount of fiber per cereal and its rating, split up by brand. …is shorthand for… ggplot(menu_subset, aes(Category, Sugars, fill = Category)) +įinally, the last dataset tht we’ll use-which was also made available through -contain nutritional information from about 80 different kinds of cereal. In other words… m + ggtitle("A Default Plot") mĬonveniently for us, if I want to make changes to the plot, I can just add additional lines of ggplot2 code to the p and it’ll work out like normal. So now, to plot it, all I need to do is call m. m <- ggplot(menu_subset, aes(Category, Sugars, fill = Category)) + For the color, I’ll use Paul Tol’s themes, which I access using the package ggthemes. The default plot will just be the distribution of the number of sugars in each of the four remaining categories. Menu_subset <- subset(menu, Category %in% c("Smoothies & Shakes", "Desserts", "Beverages", "Snacks & Sides")) To make that subset, I’ll use the subset function. To simplify things a little bit, I’ll take a subset-just four of the nine categories. 1.1 Amount of sugar per McDonald’s categoryįor some of the workshop, I’ll work with the McDonald’s menu items dataset, which you can access from my wesite.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |