Ggplot2_Error: geom_point requires the following missing aesthetics: y

I am trying to run the rWBclimate package in RStudio. I copied the code below from ROpenSci and pasted it into RStudio. But I get the error "I don’t know how to automatically select the scale for the type list object. Default Error: geom_point requires the following missing aesthetic properties: y

gbr.dat.t <- get_ensemble_temp("GBR", "annualavg", 1900, 2100)

## Loading required package: rjson

### Subset to just the median percentile
gbr.dat.t <- subset(gbr.dat.t, gbr.dat.t$percentile == 50)
## Plot and note the past is the same for each scenario
     ggplot(gbr.dat.t,aes(x=fromYear,y=data,group=scenario,colour=scenario))    
+ geom_point() +
geom_path() +
theme_bw() +
xlab("Year") +
ylab("Annual Average Temperature in 20 year increments")

I also tried using geom_point (stat = "identity") as follows, but did not work:

ggplot(gbr.dat.t,aes(x=fromYear,y=data,group=scenario,colour=scenario))    
+ geom_point(stat="identity") +
geom_path() +
theme_bw() +
xlab("Year") +
ylab("Annual Average Temperature in 20 year increments")

I still get the same message, “I don’t know how to automatically select the scale for a type list object. Error: geom_point requires the following missing aesthetic properties: y”

In addition, the result of str (gbr.dat.t) is shown below:

> str(gbr.dat.t)
'data.frame':   12 obs. of  6 variables:
$ scenario  : chr  "past" "past" "past" "past" ...
$ fromYear  : int  1920 1940 1960 1980 2020 2020 2040 2040 2060 2060 ...
$ toYear    : int  1939 1959 1979 1999 2039 2039 2059 2059 2079 2079 ...
$ data      :List of 12
..$ : num 9.01
..$ : num 9.16
..$ : num 9.05
..$ : num 9.36
..$ : num 10
..$ : num 9.47
..$ : num 9.92
..$ : num 10.7
..$ : num 10.3
..$ : num 11.4
..$ : num 12.1
..$ : num 10.4
$ percentile: int  50 50 50 50 50 50 50 50 50 50 ...
$ locator   : chr  "GBR" "GBR" "GBR" "GBR" ...

Look for helpful answers.

+4
1

, . , , gbr.dat.t $

library('rWBclimate')
library("ggplot2")

gbr.dat.t <- get_ensemble_temp("GBR", "annualavg", 1900, 2100)

## Loading required package: rjson

### Subset to just the median percentile
gbr.dat.t <- subset(gbr.dat.t, gbr.dat.t$percentile == 50)

#This is the line you were missing
gbr.dat.t$data <- unlist(gbr.dat.t$data)

## Plot and note the past is the same for each scenario
ggplot(gbr.dat.t,aes(x=fromYear,y=data,group=scenario,colour=scenario)) + geom_point() +
  geom_path() +
  theme_bw() +
  xlab("Year") +
  ylab("Annual Average Temperature in 20 year increments")
+6

All Articles