Jill Rakowski
Jill Rakowski

Reputation: 11

I do not understand this Error: attempt to apply non-function

This is the code I have been attempting to run with the following result - Error: attempt to apply non-function

# install packages
install.packages("Ecdat")
install.packages("gapminder")
# run libraries
library(gapminder)
library(Ecdat)
library(ggplot2)
library(dplyr)

View(mtcars)

c <- ggplot(mtcars, aes(x = cyl,   
   y=mpg))
c + geom_col(color = blue, fill = 
  green) + 
  (main = "Car Milage Data") (xlab = 
  "Number of Cylinders") (ylab = 
  "Miles Per Gallon")

Upvotes: 0

Views: 934

Answers (1)

Vin&#237;cius F&#233;lix
Vin&#237;cius F&#233;lix

Reputation: 8826

I noted 3 things:

  • Used c as the name of the object, and it is one of the base R functions
  • The colors inside geom_col need to be characters
  • The way you used main, xlab and ylab did not have a "connector" such as +

I way to do your plot is

ggplot(mtcars, aes(x = cyl,y = mpg)) +
  geom_col(color = "blue", fill =  "green")+
  labs(
    x = "Number of Cylinders",
    y = "Miles Per Gallon",
    title = "Car Milage Data"
  )

Upvotes: 2

Related Questions