[R] Special characters in cell names
Mahmood Naderan
m@hmood@nt @end|ng |rom gm@||@com
Wed Jun 23 23:55:46 CEST 2021
OK I understand. Thanks a lot.
Regards,
Mahmood
On Wed, Jun 23, 2021 at 11:46 PM Bert Gunter <bgunter.4567 using gmail.com> wrote:
> Try:
> ggplot(mydata, aes(x=W, y=`X/Y`)) + geom_violin(trim=FALSE)
>
> Note the use of *backticks*, ``, not single quotes, ' ' . ** They are
> different.**
>
> So, yes, your data got read in correctly, presumably because "/" is
> considered a character in your locale. It is not in mine. So my suggestion
> was indeed 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 2:39 PM Mahmood Naderan <mahmood.nt using gmail.com>
> wrote:
>
>> Hi Bert,
>> I don't know what does "check.names" do here, but my commands look like
>>
>>
>> > mydata <- read.csv('r.3080..csv', header=T,row.names=1)
>>
>> > head(mydata)
>> W A X/Y
>> P1 M 1.469734 0.004144405
>> P2 M 20.584841 0.008010306
>> P3 M 53.519800 0.166034888
>> P4 M 42.308700 0.051545443
>> P5 M 99.236384 0.893037857
>> P6 M 94.279504 0.856837525
>>
>> So when I use
>>
>> p <- ggplot(mydata, aes(x=W, y='X/Y')) + geom_violin(trim=FALSE)
>>
>>
>> The output is not correct. I don't see values (scale) on the y-axis.
>> Anyway, I fixed that with a label.
>>
>> Regards,
>> Mahmood
>>
>>
>>
>>
>> On Wed, Jun 23, 2021 at 11:16 PM Bert Gunter <bgunter.4567 using gmail.com>
>> wrote:
>>
>>> 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