Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ggscatter cannot handle non-standard column names | Error in FUN(X[[i]], ...) : object 'B' not found #229

Closed
tobsecret opened this issue Dec 4, 2019 · 4 comments

Comments

@tobsecret
Copy link

Preface

I am an r-newbie, so I'm not sure whether this is an issue or expected behavior and whether this is a ggpubr or ggplot2 issue.

Expected behavior

Given a data.frame with column names that are non-valid variable names, ggscatter produces a plot given the appropriate x and y column names.

Observed behavior

Despite being able to access those columns from the data.frame in the console, ggscatter chokes if given a data.frame with non-valid column names and the corresponding x and y column names.

MCVE

Let's make two data.frames, one with check.names = FALSE (i.e. with non-valid variable name columns) and one with check.names = TRUE. We can access columns with data from each of these frames without a problem:

> library(ggpubr)
> data_names_not_checked = data.frame('A-A' = 1:10, 'B-B' = 11:20, check.names = FALSE)
> data_names_not_checked[,'A-A']
 [1]  1  2  3  4  5  6  7  8  9 10
> data_checked_names = data.frame('A-A' = 1:10, 'B-B' = 11:20, check.names = TRUE)
> data_checked_names[,'A.A']
 [1]  1  2  3  4  5  6  7  8  9 10

When we try to plot the columns using ggscatter, we get an error if we left check.names = TRUE:

> ggscatter(data_names_not_checked, x = 'A-A', y = 'B-B')
Error in FUN(X[[i]], ...) : object 'B' not found
> ggscatter(data_checked_names, x=make.names('A-A'), y=make.names('B-B'))

If we use the frame with the checked names and the appropriate corrected column names, the function succeeds.

@kassambara
Copy link
Owner

fixed now, thanks

@tobsecret
Copy link
Author

Awesome, thanks!

@kassambara
Copy link
Owner

Supporting non standard column breaks many other ggplot2 functionality. So, I think we should remove support to non-standard column names.

kassambara added a commit that referenced this issue Nov 13, 2022
@kassambara
Copy link
Owner

Now ggpubr.parse_aes global options is available. logical indicating whether to parse or not the aesthetics variables names. Default is TRUE. For example, if you want ggpubr to handle non-standard column names, like A-A, without parsing, then set this option to FALSE using options(ggpubr.parse_aes = FALSE).

# Data
 data("mtcars")
  df <- mtcars[, c("wt", "mpg")]
  colnames(df) <- c("A-A", "B-B")

# Plotting after inactivating parsing
  old_options <- options(ggpubr.parse_aes = FALSE)
  p <- ggscatter(df, x = "A-A", y = "B-B" )

# restore back old settings
  options(old_options)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants