Error in ggplot(data = mpg) : could not find function "ggplot"

Hi Guys<,

As part of my master course I have been asked to load the tidyverse with the following code
library(tidyverse)
#> ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
#> :heavy_check_mark: ggplot2 3.3.2 :heavy_check_mark: purrr 0.3.4
#> :heavy_check_mark: tibble 3.0.3 :heavy_check_mark: dplyr 1.0.2
#> :heavy_check_mark: tidyr 1.1.2 :heavy_check_mark: stringr 1.4.0
#> :heavy_check_mark: readr 1.4.0 :heavy_check_mark: forcats 0.5.0
#> ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
#> :heavy_multiplication_x: dplyr::filter() masks stats::filter()
#> :heavy_multiplication_x: dplyr::lag() masks stats::lag()

in the console I got:
Error: unexpected input in "─"

#> :heavy_check_mark: ggplot2 3.3.2 :heavy_check_mark: purrr 0.3.4
#> :heavy_check_mark: tibble 3.0.3 :heavy_check_mark: dplyr 1.0.2
#> :heavy_check_mark: tidyr 1.1.2 :heavy_check_mark: stringr 1.4.0
#> :heavy_check_mark: readr 1.4.0 :heavy_check_mark: forcats 0.5.0
#> ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
#> :heavy_multiplication_x: dplyr::filter() masks stats::filter()
#> :heavy_multiplication_x: dplyr::lag() masks stats::lag()
#> ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
#> :heavy_check_mark: ggplot2 3.3.2 :heavy_check_mark: purrr 0.3.4
#> :heavy_check_mark: tibble 3.0.3 :heavy_check_mark: dplyr 1.0.2
#> :heavy_check_mark: tidyr 1.1.2 :heavy_check_mark: stringr 1.4.0
#> :heavy_check_mark: readr 1.4.0 :heavy_check_mark: forcats 0.5.0
#> ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
#> :heavy_multiplication_x: dplyr::filter() masks stats::filter()
#> :heavy_multiplication_x: dplyr::lag() masks stats::lag()

during the lecture I have been asked to tape mpg to see what I get but in the console I got:

Error: object 'mpg' not found

Do you have an idea what am I suppose to see?

Then I was asked to type:

ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy))

in the console I got:

Error in ggplot(data = mpg) : could not find function "ggplot"

I'm stuck I can't figure out on Google what is the issue.

Does anyone could help me?

mpg, along with disp and hwy are columns/fields within a data.frame called mtcars that comes with R as an example table.

type mtcars to see it

Thank you for your response. when i tape mtcars I can a list of cars.

However, when I tape ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy))

I still get

Error in ggplot(data = mpg) : could not find function "ggplot

did you library(tidyverse) in this same session before attempting to use ggplot2 ?
you need to do the library call once in every session in which you would wish to use ggplot2 and its functions, (of which ggplot() is one). This is different from installation, which you only do once typically.

beyond that mpg is not an appropriate data for ggplot to process, rather it would be mtcars

I forgot to run the library(tidyverse) that's why I was getting the errors.

Thank you very much for your help.

Now I can read mpg too.

This topic was automatically closed 21 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.