data(mtcars)Graphs and AI
Using AI for R coding
Challenge
Go to copilot.microsoft.com use your Uni of Leeds IT account to sign in. The shield in the top right tells you it is secure. Use it in the challenges below to help you write code.
Try to get the code to run in R. If it fails try to rephrase your prompt to copilot.
Graphs
Load the data (they come with R) then recreate the two graphs by finding code on the internet for the basic graph and building on it.
Look at this Learning R webpage if you need an introduction or reminder on using ggplot to build graphs in R.
Challenge
Use this data:
Recreate this graph using the variables miles per gallon mpg, weight wt, displacement disp and automatic or manual am.

Hints
This is a scatterplot. The size of the points are weighted by disp. Points are coloured by am.
There are many ways to write code to achieve this graph.
If something doesn’t work don’t be afraid to look for alternative code.
Challenge
Use the tooth growth dataset:
data(ToothGrowth)Recreate this graph using the variable len and dose.
 
Hints
This is called a jitter plot with errorbars.
The raw data is needed for the jitter part but the mean and standard deviation values are needed for the errorbars. Therefore you may need to summarise the data.
R sometimes thinks dose is a continuous variable not a factor.
Challenge
Use the iris dataset:
data(iris)Recreate this graph using the variables species, sepal width and sepal length.

Hints
The first graph is a histogram, the second violin and jittered points and the third a scatter plot with a regression line.
Graph arrangements like this might be called subplots, panels or grids.
Reflect on using AI
Did the R code always work first time? Did you or copilot correct it?
Did you ask the AI to address two problems at once or one at a time and what worked?
Could you have been more specific in your question?
Did you give copilot the code and error?
Citing AI
The university has guidance on stating that you have used AI in an acknowledgement or declaration section at the end of your work. An example is below.
“I acknowledge the use of Copilot (copilot.microsoft.com) to write and debug parts of my R code.”
Alternatively, you could cite in the methods section what part of the work you used AI for, what software was used and what you asked it to do.
For example “The R code used to run a power analysis on the chaffinch data was written using artificial intelligence software ChatGPT 3.5 (OpenAI, 2023).
The reference would be “OpenAi. 2023. ChatGPT (26 Oct version) [Large language model]. https://chat.opanai.com/chat”