Custom annotations

Good day everyone,
Please i need assistance with the code below.

ggplot(mtcars, aes(x = mpg))+
geom_histogram((bins = 10)+
labs(x = "Miles/(US) gallon",
y = "Count",
title = "Distribution of Miles/Gallon")+
geom_vline(aes(xintercept = 19.2),
color = "red") +
annotate(geom = "text",
label = "Median = 19.2",
x = 21,
y = 7,
hjust = 0,
color = "red"))

Here's the error message i got after running the code:
Error in (bins = 10) + labs(x = "Miles/(US) gallon", y = "Count", title = "Distribution of Miles/Gallon") :
non-numeric argument to binary operator

check your brackets, you've got one extra in
geom_histogram((bins = 10)+

In RStudio, you may want to enable Tools > Global Options > Code > Display > Use rainbow parenthesis.

1 Like

Thank you. I've been able to run the code.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.