How to deal with spaces in my variables?

51 views
Skip to first unread message

Mouna Belaid

unread,
Jun 20, 2016, 6:52:10 AM6/20/16
to ggplot2
Hello
How are you?
In my table there is this variable " pollution car" and as you notice here there is a space between "pollution" and "car" but while using ggplot2 and typing aes(x=pollution car........)
I don't get what I want as there is a space, what should I do?
Please help me

Ben Bond-Lamberty

unread,
Jun 20, 2016, 7:20:19 AM6/20/16
to Mouna Belaid, ggplot2
You can refer to this using backticks, e.g. x$`pollution car` or
aes(`pollution car` = size).
Ben
> --
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example:
> https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ggplot2" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ggplot2+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Roman Luštrik

unread,
Jun 20, 2016, 8:35:50 AM6/20/16
to Mouna Belaid, ggplot2
Hi,

my suggestion would be to keep your data tidy and eliminate leading number, spaces and special characters from variable names. This makes the code more robust and transferable.

Please also note that this is a ggplot2 related mailing list and more appropriate venues for these sort of questions exist. A search of the internet using your favorite google search engine may yield relevant results and if not, feel free to post (also general and ggplot2 related) questions to StackOverflow. Note that this site has a powerful search engine with 141000 questions on R. Chances are there's already an answer, somewhere.

Cheers,
Roman

--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
In God we trust, all others bring data.

Mouna Belaid

unread,
Jun 20, 2016, 2:05:24 PM6/20/16
to ggplot2
I highlly appreciate your help! Thank you.

Mehmet Gültaş

unread,
Jun 25, 2016, 2:51:45 AM6/25/16
to ggplot2
According to a post that I found in stackoverflow using backticks should solve your problem. I tried it, it works.
http://stackoverflow.com/questions/4551424/how-to-refer-to-a-variable-name-with-spaces

Mouna Belaid

unread,
Jun 25, 2016, 3:03:24 AM6/25/16
to ggplot2
Thank you
Reply all
Reply to author
Forward
0 new messages