AI-assisted plotting with R and Positron

Using GitHub Copilot integrated with Positron to improve your plots

ggplot2
GitHub Copilot
LLM
AI
dataviz
plotting
tidyverse
Author
Affiliation

Jessica Cooperstone

Presented on

September 17, 2026

Page last modified

September 16, 2026



1 Introduction

1.1 What we’ll cover

Developments in generative artificial intelligence (AI) using large language models (LLMs) is revolutizing the way the people code. We have covered in many past Code Clubs how to use ggplot2 in R to make the plots of your dreams, and today we are going to talk about aiding that process using AI.

By the end of the session, you should be more comfortable with using AI to aid in your plotting. Specifically, we’ll cover:

  • The basics of ggplot2 syntax
  • Using AI to make a simple plot
  • Using prompts to refine that plot more
  • Prompting to make a much more complicated figure

Discussion

  • Do you currently use AI to help with your plotting?
  • If yes, how do you integrate AI into your workflow?
  • Do you consider yourself familiar with the basics ggplot2?

1.2 Before we start

We are going to be working in Positron for the rest of the semester. If you haven’t done so already, please:

  1. Install Positron: download the appropriate installer from the download page, and run it. There are installers for Windows, macOS, and Linux.

  2. Make sure you have a recent R (4.4.0 or higher) installed; Positron does not come with its own copy of R.

ImportantUsing an OSU-managed computer and have no admin rights?

You should still be able to install Positron, just do so at the user level rather than system-wide.

On a Mac, this involves dragging the Positron app into your User Applications folder, /Users/<username>/Applications (i.e. this Applications folder is in the same parent folder as your Documents, Downloads, and Desktop folder).

On Windows, the Positron installer has a “User install” option. Look for a checkbox or dropdown labeled “Install for me only” (vs. “for all users”) during setup — that keeps the install in your user profile without needing admin rights.

2 Getting started

Go ahead and start Positron! It should look something like this:

Screenshot of the Positron IDE, with the Editor, Console, and various panes

2.1 Opening a folder (replaces RStudio Projects)

On the left side of the Positron window, you should see something similar to what’s shown in the screenshot on the right, prompting you to open a folder.

“Opening a folder” is Positron’s equivalent of opening an RStudio Project. The idea is the same: a folder is a self-contained workspace, and opening it sets your working directory and gives you a fresh R session.

But instead of requiring the special .Rproj file that is created when you make an RStudio Project, Positron simply treats any folder you open as a project.

Positron welcome screen, with a button to open a folder

Let’s open a new folder for today’s session:

  1. You can use the folder you created last month when you learned about Positron from Jelmer, or you can create a new folder to use today. You can create it in any way, such as with your computer’s File Explorer / Finder.

    I would suggest putting this folder within a folder for Code Club, for example: Documents > codeclub > 26-au (or put another way: ~/Documents/codeclub/26-au). Again, it would be fine to use the same folder from our August session.

  2. Open this folder in Positron by clicking the Open Folder button shown above1.

  3. Positron will reload and ask whether you want to trust the folder. Click Yes, I trust the authors and optionally check the box above it.

Positron dialog asking whether to trust the folder you just opened

The dialog for trusting a folder.

Why are Projects or open folders needed? These encourage good practices:

  • Keep each research project in its own self-contained folder
  • Use paths relative to the folder root, not absolute paths
  • Avoid using setwd()

They also make a lot of Positron’s features work better, such as the Explorer, Search, and version control support.

2.2 Setting up Posit Assistant

2.2.1 Get a GitHub account if you don’t have one

In order to use GitHub Copilot, you must have a GitHub account.

Create a GitHub account by going to github.com/join.

  • You will have to link to an email address. You can use your OSU email or a personal one, it doesn’t matter.
  • You will have to pick a username. Some advice for picking a username:
    • Incorporate your actual name - it’s useful for seeing who you are
    • Pick a username you’d be comfortable with an employer seeing
    • Shorter is better
    • Recommend to use all lower case letters
    • Your username can be changed but its annoying so try and get it right the first time
Tip

You can sign up for GitHub education with your OSU email by confirming your status as a student GitHub Education page.

You have access to Copilot free with your GitHub account.

2.2.2 Set your LLM provider to GitHub Copilot

In order to set up the Posit Assistant for AI-assisted plotting, you will need to install the Posit Assistant extension.

To do that, call up your Command Palette (Cmd/Ctrl+Shift+P), and we are going to configure which LLMs our Posit Assistant can use. Type in “Authentication: Configure Language Model Providers” and select it.

Authentication: Configure Language Model Providers

This may be because:

  • You have an old version of Positron installed. Go to the Positron site and download/install the newest version.
  • You don’t have the Posit Assistant extension installed.
    1. Open the Extensions view in Positron by clicking the Extension icon in the Activity Bar (the narrow leftmost sidebar).
    2. In the search box, start typing “Posit Assistant”
    3. Click Install on the “Posit Assistant” extension by Posit Software, PBC.

Posit Assistant extension in the Extensions view of Positron

This will prompt opening a new window where you can select which LLM provider you want to use. There are more options than what you can see in the screenshot below.

Configure Language Model Providers

Today we are going to select GitHub Copilot, which is free to use for students and academics. You will need to have a GitHub account and sign in to GitHub Copilot. Go ahead and click the orange Connect Positron to GitHub Copilot. A new pop up with open that says “The extension ‘Authentication’ wants to sign in using GitHub. Click the blue Allow. This will open a new browser window where you can sign in to GitHub and authorize Posit Assistant to use GitHub Copilot.

Connect to GitHub Copilot

The extension 'Authentication' wants to sign in using GitHub

Next you will get popup that includes a code for authenticating in your browser. You can click Copy & Continue to Browser and the 8 digit code will be added to your clipboard and a browser will open.

A pop up including your code for authenticating with GitHub.

You will need to be logged into a GitHub account to do this - you can see that mine shows up below. You might also have the option here to log in.

Selecting a log in for activating your device with GitHub

Now you can authorize your device to use GitHub Copilot with Positron. Your code should be ready in your clipboard, you can paste it here using (Cmd/Ctrl+V)

Authorize your device by entering the code you previously copied to your clipboard. It also says what GitHub user you are signed in as

Now you can authorize VS code to access items within your GitHub account. Yours might look different than mine depending on what groups you are involved with. You can press the green button to Authorize Visual-Studio-Code.

Authorize yVS Code to access your GitHub account with the username you've previously indicated. This allows existing access to reading user profile data, controlling private repos, access user email address and update github action workflows. along with some community access.

Now you should be connected.

Congratulations! You have successfully connected to GitHub Copilot!

While preparing the material for today’s session, I set up GitHub Copilot in Positron about 5 times. Sometimes when I would set up, I would get the pop up on the bottom right of my Positron window:

You have not yet finished authorizing this extension to use GitHub. Would you like to try a different way? (personal access token).

If you get this prompt, you can click the orange Yes. This will initiate a new popup that asks if you want to Continue to GitHub to create a Personal Access Token (PAT). You can click the blue Continue to GitHub.

A pop up asking if you want to Continue to GitHub to create a Personal Access Token (PAT).

You should next get a popup asking “Do you want Positron to open the external website?” and you can click the blue Open.

Positron is asking if you want Positron to open the external website.

This will bring you to your GitHub account online where you can create a Personal Access Token (PAT). You can do this with all the defaults, and you will need to set an expiration date. GitHub recommends you set at 30 days but you can do longer.

Your PAT will then be created and you can see it. Be sure to copy this, and I like to save this token also in my password manager. Then you can navigate back to Postrion where there should be a prompt asking you for this PAT.

Paste your PAT and press Enter. You should now be connected to GitHub Copilot through Positron.

2.3 Starting an R session

Near the top-right corner of the Positron window is the so-called interpreter picker, which lets you choose which installation of R (or Python) to use for your session.

If Positron found your R installation, it may have started a session already — then it would look similar to what’s shown in the screenshot on the right (with the R version number corresponding to what you have installed).

3 Re-familiarizing ourself with ggplot2 syntax

Perhaps it is possible now to use AI to make your plots without understanding any ggplot2 or R syntax, but I do think it is much easier, and you’ll have a better time if you understand the basics.

3.1 Installing and loading the tidyverse

Before we start going through the syntactical basics, we need to have ggplot2 installed in R. If you were here last time, you’ll already have the tidyverse (and ggplot2 is one of the packages contain in this meta-package), but if you weren’t then you will need to first download it using install.packages(). Then you can load the tidyverse by calling it with the function library().

library(tidyverse)
Warning: package 'ggplot2' was built under R version 4.5.2
Warning: package 'tidyr' was built under R version 4.5.2
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.1     ✔ stringr   1.6.0
✔ ggplot2   4.0.2     ✔ tibble    3.3.0
✔ lubridate 1.9.4     ✔ tidyr     1.3.2
✔ purrr     1.2.0     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors

We are going to use the penguins dataset that comes preloaded with base R. If you want to see all of these datasets, you can run library(help = "datasets")

glimpse(penguins)
Rows: 344
Columns: 8
$ species     <fct> Adelie, Adelie, Adelie, Adelie, Adelie, Adelie, Adelie, Ad…
$ island      <fct> Torgersen, Torgersen, Torgersen, Torgersen, Torgersen, Tor…
$ bill_len    <dbl> 39.1, 39.5, 40.3, NA, 36.7, 39.3, 38.9, 39.2, 34.1, 42.0, …
$ bill_dep    <dbl> 18.7, 17.4, 18.0, NA, 19.3, 20.6, 17.8, 19.6, 18.1, 20.2, …
$ flipper_len <int> 181, 186, 195, NA, 193, 190, 181, 195, 193, 190, 186, 180,…
$ body_mass   <int> 3750, 3800, 3250, NA, 3450, 3650, 3625, 4675, 3475, 4250, …
$ sex         <fct> male, female, female, NA, female, male, female, male, NA, …
$ year        <int> 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007…

The basics of ggplot2 from the RStudio ggplot2 cheatsheet

Let’s start with an example and then we’ll go through it.

penguins |> 
  ggplot(aes(x = bill_len, y = bill_dep)) +
    geom_point()
Warning: Removed 2 rows containing missing values or values outside the scale range
(`geom_point()`).

4 Making a simple plot

Before we can make any plots, let’s read in some data.


Bonus exercise: Open one of your own projects

  1. Use File > Open Folder... to open a folder that corresponds to one of your own projects with R scripts and data files.

  2. Open a script you know well, and run the first few lines of it.

  3. Open one of your own data objects in the Data Explorer.

Does anything stand out?


NoteFurther resources

::::: ::::::

Back to top

Footnotes

  1. Or if that’s somehow not showing, by using the menu File > Open Folder....↩︎