R - Ggplot function unable to run over multiple lines
Clash Royale CLAN TAG#URR8PPP
R - Ggplot function unable to run over multiple lines
For some reason ggplot has a hard time running when the code is split into multiple lines. For example this line of code will run (but is long and difficult to work with):
ggplot(mapping = aes(x = weight, y = horsepower)) + geom_point(size = 3) + labs(x = "Vehicle weight (lbs.)", y = "Engine Horsepower") + ggtitle("Weight vs. Horsepower")
However, these lines of code, which fit into the tidyverse style guide, will not run:
ggplot(mapping = aes(x = weight, y = horsepower)) + geom_point(size = 3)
+ labs(x = "Vehicle weight (lbs.)", y = "Engine Horsepower")
+ ggtitle("Weight vs. Horsepower")
I'm not sure what I'm doing wrong, and my searches haven't turned up anything.
The error I am getting is:
Invalid argument to unary operator calls
+
Can you give reference where in tidyverse style guide is says OK to put
+
on the newline?– PoGibas
9 mins ago
+
2 Answers
2
Try putting the +
operator at the end of each previous line.
+
You need to have the + sign at the end of each line.
Like
ggplot(data,aes(x,y)) +
geom_line()
Not
ggplot(data,aes(x,y))
+ geom_line()
Similarly, you would also need the similar approach when using dplyr pipe (%>%)
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Try putting the
+
operator at the end of each previous line.– MusTheDataGuy
9 mins ago