• 10. Tools for BetteR plots
Motivating Scenario:
You’ve successfully created a basic ggplot
, but now you want to make it look good. You know exactly what you want: the legend moved to the bottom, larger axis labels, a custom color palette, etc. but can’t figure out how to do it. Rather than spending hours in pain you ask: Which resources can I leverage to make this plot nice, and how can I use them?
Learning Goals: By the end of this subchapter, you should be able to:
- Adopt a problem-solving mindset for coding by:
- Focusing on strategies for finding answers rather than knowing everything.
- Identifying the part of your code you need.
- Navigate and use key resources to find solutions by:
- Quickly finding relevant examples in books and blogs.
- Reading R’s built-in
help()
files.
- Leverage modern tools to accelerate your workflow by:
- Using graphical tools like the
ggThemeAssist
RStudio add-in to generate theme code automatically. - Knowing how and when to effectively google for help.
- Using Generative AI (e.g., ChatGPT) responsibly to explain concepts, debug code, and suggest solutions.
- Using graphical tools like the
- Know how and when to ask people for help by preparing a clear, concise question with a minimal reproducible example.
How to get good at making nice figures
Making nice figures can be super fun, and getting good at this is a great skill… but it’s also somewhat “encyclopedic” – more about memorization and knowing your options than creativity. So I think there are two mindsets we can take toward learning how to get good at making plots:
This section is relevant for all coding in all languages This is simply the first time in the book I found it relevant.
🤮 Rote memorization of the “encyclopedic” stuff is boring and frustrating. No one wants to memorize weird ggplot things, and it feels shitty when you don’t know a specific trick.
🫶 Building a problem-solving toolkit while making nice plots is super empowering.
I therefore focus on the latter strategy – rather than spending time memorizing all the ways to bend ggplot
to your will, there are a bunch of resources (below) that help us learn by doing (or at least learn as we are doing). To me, this is the best way to learn.
A key to getting help is figuring out what you actually need help with. Regardless of which tool you use (AI, a friend, Google, or a book) the first step is getting clear on what part you can do, and what part you’re stuck on. That separation makes it way easier to ask a good question, get a useful answer, and move forward.
No need to memorize anything: We just need to get good at using the available tools and knowing when to use which. The even better news is that by using these tools regularly and effectively, you’ll actually get better at making good plots on your own!
Books & Blogs
In my view, a good book or blogpost is the best way to learn (This is why I am writing this book, after all, and why I include additional resources in each chapter). Authors intentionally and patiently walk through the details of how to do something, and provide concepts and context to understand how and why it works. You don’t need to read any of these cover-to-cover. Think of them more like cookbooks or survival guides: flip to the bit you need (or use the search feature), get the idea, and move on. As noted above, a key is knowing what you need!
A problem with a book is that it may not have exactly the thing you need right now, and might it not get to the point quickly. In theory if you master the material in a book you are likely to be able to do more complex stuff, but we don’t always have time for that. Sometimes we want the answer fast!
For more advanced plotting and customization, take a look at these excellent resources:.
Helpfiles
The help()
function in R can provide fast information on how to use a specific function. For me helpfiles are incredibly useful, but they take some expertise to use effectively:
First you must know the function you need help with. This isn’t always easy, as if you knew the function you might not need help. If you don’t know the function you need, or you can’t make sense of the helpfile, try google!
Second, even if you know the function you need help with, helpfiles can be hard to read. Reading helpfiles is actually a skill. See this nice resource to walk you through using a helpfile.
I suggest skimming the helpfile and pay the most attention to
Description
: What the function does.
Usage
: How to run the function.
Arguments
: What you give the function.
Examples
: Some examples of using the function.
Between a help file and ChatGPT lies a sweet spot: custom RAGs – language models trained on specific documentation. For example, the top right of https://ggplot2.tidyverse.org has a button labeled “Ask AI”. Clicking it brings you to a language model trained specifically on the help files for dplyr
, ggplot2
, and tidyr
. It gives you answers grounded in the actual docs - without the pain of learning how to read them.
Or paste the help()
output into your favorite LLM and ask it to help you understand how to read the helpfile and use the function.
Google and Stackoverflow
There is a lot of information on the internet, and Google is your friend. If you don’t know how to do something, try googling it. Often Google searches lead to answers on stackoverflow a question and answer website for computer science.
Don’t ask questions on stackoverflow Instead find answers there. Stackoverflow is not a particularly friendly place, they are not gentle with noobs, and get upset when a question you asked could be answered by anything written in the history of stackoverflow.
Googling is trickier than it sounds. Like making sense of help
, knowing the appropriate search term, separating helpful from unhelpful answers and identifying where the useful information in a webpage is are all skills. These skills require practice and basic knowledge of R. Therefore you will see these tools become more valuable as you get more confident with R.
Sometimes R doesn’t do what you want and spits out an error message
ggplot(aes(x = pull(iris,Sepal.Length),
y = pull(iris,Petal.Length))) +
geom_point()
Error in `fortify()`:
! `data` must be a <data.frame>, or an object coercible by `fortify()`,
or a valid <data.frame>-like object coercible by `as.data.frame()`, not a
<uneval> object.
ℹ Did you accidentally pass `aes()` to the `data` argument?
GUIs
The ggThemeAssist
package provides a graphical user interface (GUI) that allows you to point and click your way to the desired figure. It then generates the corresponding R code for you (see Figure 1). I learned everything I know about the theme()
function (a way to change font size, plot color etc…) from ggThemeAssist
.
As of this writing ggplot changed the syntax for placing legends in a plot, so ggThemeAssist
’s advice is wrong in that instance.
To use ggThemeAssist
:
- Install and load the package.
- Create a
ggplot
in your R script. - Select ggplot Theme Assistant from the add-ins drop-down menu.
- A GUI will appear. Point and click your way through the options, and the corresponding R code will be inserted into your script.

ggThemeAssist
package from the ggThemeAssist
website. Do yourself a favor and use this package.
People
Friends, peers, mentors etc are the most valuable and useful help you can ask for - they often know where you’re coming from, and have had experiences similar to you. The problem is that people have limited bandwidth, limited patience, and don’t know everything. As in all cases in which we seek help, the clearer we can state our goal, and the more we can isolate our challenge the more useful the help we get will be.
Generative AI
I wrote this in June 2025 GenAI is rapidly evolving, and ?might? get better/change by the time you read this. We currently don’t know the future impact of LLMs and coding / stats / jobs etc…
LLMs are trained on a huge amount of public code and documentation But training doesn’t always reflect the most up-to-date info. In my experience LLMs are particularly bad with obscure R packages. In these cases LLMs often guess plausible but incorrect syntax.
When a friend isn’t available, there’s generative AI (e.g., Claude, ChatGPT, and the like). Unlike friends, GenAI tools have infinite patience and access to way more information. I encourage you to use them to improve your figures when necessary - but I also feel compelled to offer a few warnings and bits of guidance.
GenAI is most useful when you already know what you’re doing.
I’m pretty good at coding in R. When I ask ChatGPT or Claude for help, it’s amazing. It shows me useful ways to solve problems. When the answer isn’t quite right (and it often isn’t), I can fix it or build from it.
By contrast, I know next to nothing about JavaScript. If I ask ChatGPT a JavaScript question and the answer is perfect, I’m in luck. But if it’s even a little off, I end up in a 90-minute debugging session with an LLM—and I’m no closer than when I started.
Don’t trust generative AI to be correct These things are bullshitters. They don’t understand thing. They are written to please us. I could go on about the limitations of LLM’s - but I love them for making plots because it is so easy to see if they worked (does the plot look how I wanted it too) or not.
Know when to quit (or at least change prompts)
If you are going in circles with your favorite LLM about how to make your plot how you want and it’s just not working, take a step back. Think. Is this something GenAI cannot solve? Do I need to change my prompt? Do I need to think differently about the problem? etc.. Don’t waste hours here.
Asking ChatGPT a question and copy-pasting the code it gives you might work. But if you want to actually learn—and avoid painful bugs—try this:
- Read the code.
- Read the explanation it gives you.
- Run the code in R and see what happens. PAY ATTENTION. Is this what you wanted?
- If the code doesn’t work as expected, tweak the code to have it do something slightly different. This helps make sure you understand what it’s doing.
- If the code doesn’t work as expected, go back to ChatGPT, books, or Google. Iterate until you understand what’s going on.
- If the code doesn’t work as expected, tweak the code to have it do something slightly different. This helps make sure you understand what it’s doing.
GenAI is really good with error messages When we Googled the error message above, the best answer was the automatic one from generative AI. Googling error messages can work, but often this sends us in the wrong direction because the error message does not light up the right keywords.
Do not share any data with a generative AI tool (e.g., ChatGPT, Claude) that you wouldn’t be comfortable posting publicly. Once your data is submitted to an LLM, it’s not uniquely yours anymore. If you’re working with sensitive or private data, do not paste them into a standard chatbot.
- Use fake data with the same structure.
- Use a built-in R dataset (like
penguins
,iris
, ormtcars
) with a similar shape.