r - ggplot2_Error : geom_point requires the following missing aesthetics: y

标签 r ggplot2

我正在尝试在 RStudio 中运行 rWBclimate 包。我从 ROpenSci 复制了以下代码并粘贴到 RStudio 中。但是我收到错误消息“不知道如何为列表类型的对象自动选择比例。默认为连续
错误:geom_point 需要以下缺失的美学: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")

我还尝试通过以下方式使用 geom_point(stat="identity") 但没有奏效:
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")

我仍然收到相同的消息“不知道如何为列表类型的对象自动选择比例。默认为连续
错误:geom_point 需要以下缺失的美学:y"

此外,str(gbr.dat.t) 的结果如下:
> 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" ...

寻找您的有用答案。

最佳答案

希望这可以帮助。我所做的只是将 gbr.dat.t$data 转换为数字向量

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")

关于r - ggplot2_Error : geom_point requires the following missing aesthetics: y,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29459866/

相关文章:

r - 从 R 中的插值样条获取多项式系数

r - 如何在 direct.label 中更改字体大小?

R聚类-带有观察标签的轮廓

r - ggplot2:将两个模型的 RMSE 值添加到每个方面

ggplot2 geom_order中的反向堆叠顺序

r - 在向量中查找第一个 TRUE 值的更快方法

r - 如何在函数 ggplot 中添加子图?

r - 将世界地图分为特定国家/地区的面板

R:ggplot2,我可以让 facet/strip 文本环绕吗?

r - 如何在 ggplot2 stat_summary 图中设置多种颜色?