全部版块 我的主页
论坛 提问 悬赏 求职 新闻 读书 功能一区 学道会
2903 1
2019-09-07
具体代码:
install.packages("gcookbook")
install.packages("ggplot2")
library(gcookbook)
library(ggplot2)
csub<-subset(climate,Source=="Berkeley"&Year>=1900)   #记住,这个Source的S一定要大写,因为它来源于gcookbook包的                                                                                        climate中的数据
csub$pos<-csub$Anomaly10y>=0    #变量pos对取值正负情况进行标识

csub
ggplot(csub,aes(x=Year,y=Anomaly10y,fill=pos))+geom_bar(stat = "identity",position="identity")
#pos映射给填充色参数fill
#ggplot2一般是使用“+”号,接后面的代码
#geom_bar绘制条形图
#position="identity"可避免系统对负值绘制堆积条形而发出警告信息
#但是这样画出来的图红色对应负值,蓝色对应正值

#下面代码对颜色进行调整
ggplot(csub,aes(x=Year,y=Anomaly10y,fill=pos))+geom_bar(stat = "identity",position="identity",
                                                        colour="black",size=0.25)+scale_fill_manual(values = c("#CCEEFF","#FFDDDD"),
                                                                                                    guide=FALSE)
#scale_fill_manual()参数对图形颜色进行调整
#guide=FALSE可以删除图例
#colour设定边框颜色(这里为图形加一个黑色的边框)
#size是设定边框线宽度的参数,单位是毫米


Global climate temperature anomaly data from 1800 to 2011
Description

[size=13.3333px]This data set includes estimated global temperature anamoly data for the years 1800 through 2011. The anomaly is the difference from the baseline temperature, which is the mean of the yearly temperatures from 1951-1980.

Variables
  • Source: Data source (Berkeley, CRUTEM3, NASA).
  • Year: Year for the estimate.
  • Anomaly1y: Temperature anomaly in Celcius, smoothed over one year.
  • Anomaly5y: Temperature anomaly in Celcius, smoothed over five years.
  • Anomaly10y: Temperature anomaly in Celcius, smoothed over ten years.
  • Unc10y: Uncertainty for 10-year-smoothed anomaly.
Source

[size=13.3333px]Berkeley Earth Project: http://berkeleyearth.org/dataset/

[size=13.3333px]Climatic Research Unit (CRUTEM3):http://www.cru.uea.ac.uk/cru/data/temperature/

[size=13.3333px]NASA: http://data.giss.nasa.gov/gistemp/


[size=13.3333px][Package gcookbook version 1.0 Index]

KEYD]JB6U28TG0QGP9SNKI3.png
上表是csub显示出的数据集

Rplot.png
下面对画出来的距平图进行修改
Rplot01.png
可以看到经过修改后,作为暖色的红色表示距平的正值,而蓝色表示负值。


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2019-9-7 20:22:52
csub$pos<−csub$Anomaly10y>=0

加粗字体的修改
附件列表
W{E@X)GIT4`OWNWKX$FJP~H.png

原图尺寸 6.85 KB

W{E@X)GIT4`OWNWKX$FJP~H.png

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群