One error you may encounter in R is:
Don't know how to automatically pick scale for object of type function. Defaulting to continuous.
This error occurs when you attempt to create a plot using ggplot2 but provide the name of a built-in R function (such as mean, median, max, sample, range, etc.) to the aes() argument.
This tutorial shares exactly how to fix this error.
How to Reproduce the Error
Suppose we have the following data frame in R that shows the mean number of points scored by players on different basketball teams:
#create data frame
df <- data.frame(Team=c('A', 'B', 'C', 'D'),
Mean=c(12, 22, 30, 31))
#view data frame
df
Team Mean
1 A 12
2 B 22
3 C 30
4 D 31
Now suppose we attempt to create a bar plot to visualize this data using ggplot2:
library(ggplot2)
#attempt to create bar plot
ggplot(df, aes(Team, mean)) +
geom_bar(stat='identity')
Don't know how to automatically pick scale for object of type function.
Defaulting to continuous.
We receive an error because we used mean within the aes() argument, which is the name of a default function in R.
How to Fix the Error
The way to fix this error is to simply spell the variable name exactly as it is spelled in our data frame: Mean.
When we spell the variable name this way, we don’t receive any error when creating the bar plot:
library(ggplot2)
#create bar plot
ggplot(df, aes(Team, Mean)) +
geom_bar(stat='identity')
Notice that we’re able to create the bar plot successfully without any error this time.
Additional Resources
The following tutorials explain how to troubleshoot other common errors in R:
How to Fix in R: Error in as.Date.numeric(x) : ‘origin’ must be supplied
How to Fix: Error in stripchart.default(x1, …) : invalid plotting method
How to Fix: Error in eval(predvars, data, env) : object ‘x’ not found