Q is for qplot versus ggplot
This article is originally published at http://www.deeplytrivial.com/Two years ago, when I did Blogging A to Z of R, I talked about qplots. qplots are great for quick plots - which is why they're named as such - because they use variable types to determine the best plot to generate. For instance, if I give it a single continuous variable, it will generate a histogram.
reads2019 <- read_csv("~/Downloads/Blogging A to Z/SaraReads2019_allrated.csv",
col_names = TRUE)
qplot(Pages, data = reads2019)
reads2019 <- reads2019 %>%
mutate(Fiction = factor(Fiction,
levels = c(0,1),
labels = c("Non-Fiction", "Fiction")))
qplot(Fiction, data = reads2019)
There are nearly endless ways to customize a ggplot - transforming scales, adding color schemes, layering data, changing fonts - that allow you make a fancy, schmancy, publication-ready plot. If you plan on publishing or presenting your work, you really want to use ggplots instead of qplots. qplots are like the first draft of your manuscript - no one sees it but you. But, in this case, it's a first draft that you can skip right over; just go straight to the good-looking plot.
Second, you notice that I didn't use the main pipe for my qplots above. That's because if you try it, you get an error.
## Error in FUN(X[[i]], ...): object 'read_time' not found
ggplot really is the more powerful, prettier, endlessly customizable approach to plotting data. It can be challenging to get the hang of it at first, and it's okay to ease your way into it. There are many great resources out there for learning the ggplot2 package, and specifically the ggplot function of that package. To start, check out this great cheat sheet. You can also check out Hadley Wickham's book, which he is offering free online. (Hadley Wickham, by the way, developed the ggplot2 package, along with many others.)
Hopefully you're enjoying this series so far!
Please visit source website for post related comments.