Function Errors
ggplot2 data must be a data frame
Matches: data must be a data\.frame
WHAT THIS ERROR MEANS
ggplot2 requires a data frame (or tibble) as its data argument. You passed a matrix, vector, or other incompatible type.
HOW TO FIX IT
1. Convert your data to a data frame with as.data.frame().
2. Use tibble() or data.frame() to construct the data.
3. Check the type with class(your_data).
CODE EXAMPLES
BAD — THIS CAUSES THE ERROR
mat <- matrix(1:9, nrow = 3) ggplot(mat, aes(x = V1, y = V2)) + geom_point()
GOOD — CORRECT APPROACH
df <- as.data.frame(matrix(1:9, nrow = 3)) ggplot(df, aes(x = V1, y = V2)) + geom_point()
Still stuck?
Paste your code in RChat and the AI will fix this error in context.
RELATED FUNCTION ERRORS
Function not found R doesn't recognize the function you're trying to call. The package containing i...
Unused argument You passed an argument to a function that doesn't accept it. This often happens ...
Missing required argument A function requires a specific argument that you didn't provide, and there's no ...
Argument matched multiple times You provided the same argument twice — once by name and once by position, or use...