[R] Special characters in cell names

Bert Gunter bgunter@4567 @end|ng |rom gm@||@com
Wed Jun 23 23:16:01 CEST 2021


I found your specification quite vague. What did you mean by a "data file"
-- a data frame in R? -- a file in the file system?

I may be completely wrong here, but another possibility is that you read
your data into an R data.frame via, e.g. read.table() or read.csv(), but
failed to specify the check.names = FALSE, argument. This would cause a
column named "x/y" in your original table to be given the name "x.y" in R,
as "x/y" is not a syntactically valid name. See ?make.names for details.

As others have already said, enclosing non-syntactically valid names in
back ticks usually works (maybe always works??). So for example:

z<-data.frame (`a/b` = 1:5, y = 1:5, check.names = FALSE)
plot(y ~ `a/b`, data = z) ## produces desired plot with correct label
z  ## yields:
  a/b y
1   1 1
2   2 2
3   3 3
4   4 4
5   5 5

Of course, ignore if this is all irrelevant.

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Wed, Jun 23, 2021 at 1:37 PM Mahmood Naderan <mahmood.nt using gmail.com>
wrote:

> Unfortunately, using 'X/Y' doesn't work either.
> Instead I used labels like below
>
> P + scale_y_continuous(name="X/Y")
>
> Thanks for the suggestions.
>
> Regards,
> Mahmood
>
>
>
>
> On Wed, Jun 23, 2021 at 9:22 PM Eric Berger <ericjberger using gmail.com> wrote:
>
> > If no one comes up with a better suggestion:
> > a. Change the column name to "Y" so that you get the plot you want
> > b. Use axis labels and legend text to show the text that you want. (The
> > user never has to know that you changed the column name 😃)
> >
> > HTH,
> > Eric
> >
> > On Wed, Jun 23, 2021 at 9:58 PM Mahmood Naderan <mahmood.nt using gmail.com>
> > wrote:
> >
> >> Hi
> >> I have a column in my data file which is "X/Y". With '/' I want to
> >> emphasize that values are the ratio of X over Y.
> >> Problem is that in the following command for a violin plot, I am not
> able
> >> to specify that '/' even with double quotes.
> >>
> >> p <- ggplot(mydata, aes(x=W, y="X/Y")) + geom_violin(trim=FALSE)
> >>
> >> However, if I change that column to "Y" and use
> >>
> >> p <- ggplot(mydata, aes(x=W, y=Y)) + geom_violin(trim=FALSE)
> >>
> >> Then the plot will be correctly shown.
> >> Any ideas for that?
> >>
> >> Regards,
> >> Mahmood
> >>
> >>         [[alternative HTML version deleted]]
> >>
> >> ______________________________________________
> >> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide
> >> http://www.R-project.org/posting-guide.html
> >> and provide commented, minimal, self-contained, reproducible code.
> >>
> >
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list