Hello,

Richard's answer solves the problem, I'm writing about details in the OP's post.

Ana, your code example is missing some library() calls:

library(ggplot2)
library(ggrepel)
library(ggthemes)
library(dplyr)

# and where to find the data set
data(murders, package = "dslabs")


As for the dplyr pipe, you end it with .$rate to pull only that column's value, the following avoids that construct and is, I believe, more idiomatic:

#define the slope of the line
r <- murders %>%
  summarize(rate = sum(total)/sum(population)*10^6) %>%
  pull(rate)


Hope this helps,

Rui Barradas


Às 04:27 de 08/05/20, Richard M. Heiberger escreveu:
It is just like the message suggested. You have a + at the end of each line
and
the beginning of the next.  The one at the end is required.  The ones at
the beginning are
causing the error message.

Please put spaces around your assignment arrows.
Difficult to read:  r<-murders
Easy to read:    r <- murders

On Thu, May 7, 2020 at 10:46 PM Ana Marija <sokovic.anamar...@gmail.com>
wrote:

Hello,

I got this error:
Error: Cannot use `+.gg()` with a single argument. Did you
accidentally put + on a new line?

After running this:
data(murders)
library(ggplot2)
library(dplyr)
library(ggplot2)
ggplot(data=murders)

#define the slope of the line
r<-murders %>% summarize(rate=sum(total)/sum(population)*10^6) %>%.$rate
#mamke the plot
murders %>% ggplot(aes(population/10^6,total,label=abb))+
   +geom_abline(intercept = log10(r),lty=2,color="darkgrey")+
   +geom_point(aes(col=region), size=3)+
   +geom_text_repel()+
   +scale_x_log10()+
   +scale_y_log10()+
   +xlab("Populations in millions (log scale)")+
   +ylab("Total number of murders (log scale)")+
   +ggtitle("US Gun Murders in US 2010")+
   +scale_color_discrete(name="Region")+
   +theme_economist()

Is this an issue with my dplyr? Or how I can fix this code in order to
work?

Thanks
Ana

______________________________________________
R-help@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@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.


______________________________________________
R-help@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.

Reply via email to