ggplot 2 help for my code

Hi all:
I ned help in my code:
qqplot(train.data, aes(lstat,Número.tallos.total..m2.) ) + geom_point() + stat_smooth()
Error in [.data.frame(x, order(x, na.last = na.last, decreasing = decreasing)) :
undefined columns selected

I don't really know what is causing the error, thank you for your comments

Hello Karina,
Sorry for your struggle with R. Don´t give up!
First:
If you want to receive better help from the community, you should provide a reproducible example (reprex), so people can troubleshoot your problem.
there is also a nice R package that helps you to create reprex:

Second:
back to your problem, from you errors, it seems that the code does not recognize the column name you are trying to plot (undefined columns selected). It does seems that your data have strange characters as column names like ú and .. Try correcting the column names in you train.data and run again the code.

If you want to do that automatically, and not manually, you can use the awesome "janitor" package
which has a sweet clean_names() function that automatically makes all the column names readable by R.

As a wild guess, I would do this:
library(janitor)
library(tidyverse)
toplot <- train.data %>% clean_names()

and then substitute the corrected names in your code like:

qqplot(toplot, aes(newnamecolumn1, newnamecolumn2)) + geom_point() + stat_smooth()

I am sorry but without a reproducible example, i cannot help you further.
Good luck!

Hi @R_Karina_Gonzales_Po,
Welcome to the RStudio Community Forum.

I think you have simply misspelt the function name: it should be ggplot(......) not qqplot(....).

The function stats::qqplot() does exist but this draws QQ plots and has different syntax to ggplot(), hence the error you encountered. Also note that the package ggplot2 contains a function qplot() ["Quick Plot"].

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.