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]]
Use backquotes, `X/Y`, to specify a name, not double quotes. -Bill On Wed, Jun 23, 2021 at 11:58 AM Mahmood Naderan <mahmood.nt at 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 at 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]]
On 23/06/2021 11:38 a.m., Mahmood Naderan 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?I haven't tried, but I'd expect back quotes would work: ggplot(mydata, aes(x=W, y=`X/Y`)) That's the normal way to quote a name in R. Duncan Murdoch
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 at 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 at 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]]