ggplot2_Error:geom_point需要以下缺失的美学:y [英] ggplot2_Error: geom_point requires the following missing aesthetics: y
问题描述
我试图在RStudio中运行rWBclimate软件包。我复制了 ROpenSci 中的以下代码并粘贴到RStudio中。但是我收到错误说'不知道如何自动选择类型列表对象的比例。默认为连续
错误:geom_point需要以下缺失的美学:y
gbr.dat.t< - get_ensemble_temp (GBR,annualavg,1900,2100)
##加载所需软件包:rjson
###子集到中位数百分位数
gbr .dat.t< - subset(gbr.dat.t,gbr.dat.t $ percentile == 50)
##绘制并记录每个场景的过去是相同的
ggplot(gbr ()= $ b $ geom_point()+
geom_path b $ b xlab(Year)+
ylab(20年递增的年平均温度)
我也尝试以下列方式使用geom_point(stat =identity),但无效:
ggplot(gbr.dat.t,aes(x = fromYear,y = data,group = scenario,color = scenario))
+ geom_point(stat =identity)+
geom_path() +
theme_bw()+
xlab(年)+
ylab(年平均气温20年增量)
我仍然收到同样的信息不知道如何自动挑选比例为类型列表的对象。默认为连续
错误:geom_point需要以下缺失美学:y
另外,str(gbr.dat.t)的结果如下:
> str(gbr.dat.t)
'data.frame':12 obs。6个变量:
$情景:过去过去过去过去...
$年份:int 1920 1940 1960 1980 2020 2020 2040 2040 2060 2060 ...
$ toYear:int 1939 1959 1979 1999 2039 2039 2059 2059 2079 2079 ...
$ data:12
$ $:$ 9.01
$:$ 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:chrGBRGBRGBRGBR...
$ b寻找您有用的答案。
希望这有助于我做的所有事情s将gbr.dat.t $数据转换为数字向量
$ b $ pre $ library $('rWBclimate')
library( ggplot2)
gbr.dat.t< - get_ensemble_temp(GBR,annualavg,1900,2100)
##加载所需软件包:rjson
###子集到中位数百分位数
gbr.dat.t< - 子集(gbr.dat.t,gbr.dat.t $百分数== 50)
#这是你错过的行
gbr.dat.t $ data< - unlist(gbr.dat.t $ data)
##绘图和注释每个场景的过去都是相同的
ggplot(gbr.dat.t,aes(x = fromYear,y = data,group = scenario,color = scenario))+ geom_point()+
geom_path( )+
theme_bw()+
xlab(年)+
ylab(年平均气温20年递增)
pre>I am trying to run rWBclimate package in RStudio. I copied the below code from ROpenSci and pasted in RStudio. But I get error saying 'Don't know how to automatically pick scale for object of type list. Defaulting to continuous Error: geom_point requires the following missing aesthetics: 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 to use geom_point(stat="identity") in the following way but didn't 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 "Don't know how to automatically pick scale for object of type list. Defaulting to continuous Error: geom_point requires the following missing aesthetics: y"
Also, the result from str(gbr.dat.t) is given 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" ...
Looking for your helpful answers.
解决方案Hope this helps. All I did was convert the gbr.dat.t$data to a numeric vector
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")
这篇关于ggplot2_Error:geom_point需要以下缺失的美学:y的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!