欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

使用ggplot2繪制風(fēng)向風(fēng)速玫瑰圖

系統(tǒng) 4973 0

偶然的機會,試著使用了一次ggplot2,繪出的玫瑰圖的確非常美,將使用過程記錄下來。

ggplot2

  ggplot2是用于繪圖的R語言擴展包,其理念根植于《Grammar of Graphics》一書。它將繪圖視為一種映射,即從數(shù)學(xué)空間映射到圖形元素空間。
例如將不同的數(shù)值映射到不同的色彩或透明度。該繪圖包的特點在于并不去定義具體的圖形(如直方圖,散點圖),而是定義各種底層組件(如線條、方塊)來合成復(fù)雜的圖形,
這使它能以非常簡潔的函數(shù)構(gòu)建各類圖形,而且默認(rèn)條件下的繪圖品質(zhì)就能達(dá)到出版要求。

http://www.plob.org/2014/05/11/7264.html

?

?安裝ggplot2

  • R語言環(huán)境下安裝ggplot2
      install.packages(
      
        "
      
      
        ggplot2
      
      
        "
      
      )
    

繪制風(fēng)向風(fēng)速玫瑰圖?

?

  • 載入相關(guān)依賴包

#library與require功能類似,區(qū)別是require()返回一個logic之,library返回一個類似地址的值
#library(ggplot2)
#library(RColorBrewer)
require(ggplot2)
require(RColorBrewer)

plot.windrose <- function(data,
spd,
dir,
spdres = 10, //風(fēng)速單位區(qū)間
dirres = 30, //風(fēng)向角度區(qū)間
spdmin = 0,
spdmax = 90,
spdseq = NULL,
palette = "YlGnBu",
countmax = NA,
debug = 0){

# Look to see what data was passed in to the function
if (is.numeric(spd) & is.numeric(dir)){
# assume that we've been given vectors of the speed and direction vectors
data <- data.frame(spd = spd,dir = dir)
spd = "spd"
dir = "dir"
} else if (exists("data")){
# Assume that we've been given a data frame, and the name of the speed?
# and direction columns. This is the format we want for later use.?
}?

# Tidy up input data ----
n.in <- NROW(data)
dnu <- (is.na(data[[spd]]) | is.na(data[[dir]]))
data[[spd]][dnu] <- NA
data[[dir]][dnu] <- NA

# figure out the wind speed bins ----
if (missing(spdseq)){
spdseq <- seq(spdmin,spdmax,spdres)
} else {
if (debug >0){
cat("Using custom speed bins \n")
}
}

# get some information about the number of bins, etc.
n.spd.seq <- length(spdseq)
n.colors.in.range <- n.spd.seq - 1

# create the color map
spd.colors <- colorRampPalette(brewer.pal(min(max(3,
n.colors.in.range),
min(9,
n.colors.in.range)),?
palette))(n.colors.in.range)

if (max(data[[spd]],na.rm = TRUE) > spdmax){?
spd.breaks <- c(spdseq,max(data[[spd]],na.rm = TRUE))?
spd.labels <- c(paste(c(spdseq[1:n.spd.seq-1]),
'-', c(spdseq[2:n.spd.seq])),paste(spdmax,
"-",max(data[[spd]],na.rm = TRUE)))
spd.colors <- c(spd.colors, "grey50")
} else{
spd.breaks <- c(seq(spdseq))
spd.labels <- paste(c(spdseq[1:n.spd.seq-1]),
'-',c(spdseq[2:n.spd.seq]))?
}
data$spd.binned <- cut(x = data[[spd]],
breaks = spd.breaks,
labels = spd.labels,
ordered_result = TRUE)

# figure out the wind direction bins
dir.breaks <- c(-dirres/2,seq(dirres/2, 360-dirres/2, by = dirres),360+dirres/2)?
dir.labels <- c(paste(360-dirres/2,"-",dirres/2),paste(seq(dirres/2, 360-3*dirres/2, by = dirres),
"-",seq(3*dirres/2, 360-dirres/2, by = dirres)),paste(360-dirres/2,"-",dirres/2))

# assign each wind direction to a bin
dir.binned <- cut(data[[dir]],breaks = dir.breaks,ordered_result = TRUE)
levels(dir.binned) <- dir.labels
data$dir.binned <- dir.binned

#修改上述函數(shù), 改用英文縮寫方位標(biāo)志
#dir.breaks <- c(-1, 11.25 + (22.5*0:16))
#dir.binned <- cut(data[[dir]],breaks = dir.breaks,labels = c("N", "NNE", "NE", "ENE", "E", "ESE","SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW", "N2"))
#levels(dir.binned)[17] = "N"

# Run debug if required ----
if (debug>0){?
cat(dir.breaks,"\n")
cat(dir.labels,"\n")
cat(levels(dir.binned),"\n")
cat(speedcuts.colors, "\n")?
}?

# create the plot ----
p.windrose <- ggplot(data = data,aes(x = dir.binned,fill = spd.binned)) +
geom_bar() + scale_x_discrete(drop = FALSE,labels = waiver()) +
coord_polar(start = -((dirres/2)/360) * 2*pi) +
scale_fill_manual(name = "Wind Speed (m/s)",values = spd.colors,drop = FALSE) +
theme(axis.title.x = element_blank())

# adjust axes if required
if (!is.na(countmax)){
p.windrose <- p.windrose +
ylim(c(0,countmax))
}

# print the plot
print(p.windrose)?

# return the handle to the wind rose
return(p.windrose)
}

  • 調(diào)用上述方法

#讀取數(shù)據(jù)
data.in <- read.csv(file = "H:/1.csv",col.names = c("date","hr","ws.80","wd.80"),stringsAsFactors = FALSE)

#調(diào)用方法,代入風(fēng)速風(fēng)向數(shù)據(jù),生成圖像(data.in$ws.80指代入上述讀取數(shù)據(jù)中的ws.80行,spdseq為風(fēng)速分割區(qū)間)
p <- plot.windrose(spd = data.in$ws.80,dir = data.in$wd.80,spdseq = c(0,10,20,30,40,50,60,70,80,90))

#保存圖像
ggsave("H:/test.png")

使用的數(shù)據(jù)文件

使用ggplot2繪制風(fēng)向風(fēng)速玫瑰圖

?

生成的風(fēng)向風(fēng)速玫瑰圖

使用ggplot2繪制風(fēng)向風(fēng)速玫瑰圖

使用ggplot2繪制風(fēng)向風(fēng)速玫瑰圖


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 久久综合日韩亚洲精品色 | 国产精品自拍99 | 天天艹夜夜艹 | 国产精品久久九九 | 国产欧美一级二级三级在线视频 | 日本看片一区二区三区高清 | 欧美一区二区三区成人精品 | 欧美大香线蕉线伊人久久 | 欧美日韩精品国产一区二区 | 国产一区二区三区福利 | 9久9久女女免费精品视频在线观看 | 国产婷婷色一区二区三区在线 | 久草视频免费看 | 亚洲 日本 欧美 中文幕 | 性看小视频 | 色综合伊人色综合网亚洲欧洲 | 青娱乐手机免费视频 | 另类小说综合 | 久综合| 九九精品视频在线播放 | 日韩在线观看精品 | 视频福利在线观看 | 欧洲精品色 | 欧美日韩在线免费观看 | 色哟哟哟在线精品观看视频 | 国产综合久久久久 | 日韩一区二区在线观看视频 | 亚洲免费资源 | 免费看片网址 | 成人免费毛片aaaaaa片 | 久久精品国产99久久久古代 | 亚洲精品一区二区三区婷婷月色 | 国产在线视频自拍 | 欧美色欧美亚洲另类二区精品 | 日韩免费视频一区二区 | 久久九| 久操国产视频 | 日本高清在线中文字幕网 | 欧美成人精品一区二区男人看 | 亚洲精品a级| 澳门久久精品 |