#Configuration#文件夾位於Windows PC上,“〜/”是我的文檔。路徑< - “〜/corr-test”#要顯示文件< - “ tsv105.txt”的文件的名稱#this是適用的輪廓圖的'bin寬度'。#,即,兩條線之間的差距有多大。#Lower數字顯示更多的行,更高的數字顯示較少。BW <-50#這些選擇每個圖表#Warning的顏色尺度的下層和上限!- 較低的值必須在左側#hcplimit調整半單元電勢圖#Reslimit調整電阻圖#corrlimit調整腐蝕圖HCPLIMIT hcplimit <-c(-400,-100)reslimit <-c(0,100)corrlimit corrlimit corrlimit<-c(0,300)#設置圖表將使用#for for Support顏色列表的顏色,請參見#http://sape.inf.usi.ch/quick-reference/ggplot2/colour lowcol < - “ darkred”HighCol < - “ seagreen”##script在##install packages以下開始,如果尚未安裝,如果(!上方setWD(路徑)#tract主數據集t < - read_csv2(file,skip = 3,col_names = false)for(in in ncol(t)+1:9){if(i <= 9){t [i <= 9)] <-0}} names(t)[1:9] <-c(“ xmax”,“ ymax”,“ gridx”,“ gridy”,“ tlevel”,“ tlevel”,“邏輯”,“ pulsesize”,“ rebar Length”“,“鋼筋直徑”)#take在文件的配置中,例如網格值f <-t%>%突變(id = seq.int(nrow(t)))%>%filter(str_detect(xmax,“:”))%>%>%top_n(1,id)%>%>% as.list() #Tidy up the data a bit: #We select only the columns we need #We rename them sensibly #Filter to only the rows we're interested in #Get rid of extreme values #And get rid of duplicates s <- t %>% mutate(ID = seq.int(nrow(t))) %>% select(ID, Xmax, Ymax, GridX, GridY) %>% rename(x=Xmax, y=Ymax, type = GridX, value = GridY) %>% filter(type %in% c(0,1,2,3)) %>% filter(!str_detect(x, ":")) %>% filter(!str_detect(x, "\\$")) %>% mutate(x=as.numeric(x), y=as.numeric(y), value=as.numeric(value)) %>% filter(value < 2000) %>% arrange(x, y, -ID) %>% group_by(x,y, type) %>% filter(row_number() == 1) #Create a bunch of datasets in one place, named so it's easier to remember which is which chartdata <- c() chartdata$hcp <- s %>% filter(type == 0) chartdata$res <- s %>% filter(type == 1) chartdata$corr <- s %>% filter(type == 2) #Get the grid multipliers for our data. If set to 0, give a multiplier of 1. xgrid <- if_else(as.numeric(f$GridX) == 0, 1, as.numeric(f$GridX)) ygrid <- if_else(as.numeric(f$GridY) == 0, 1, as.numeric(f$GridY)) #Get the outer bounds to use for the charts. minx <- min(chartdata$hcp$x) maxx <- max(chartdata$hcp$x) miny <- min(chartdata$hcp$y) maxy <- max(chartdata$hcp$y) #This function sets up the majority of a chart #It is passed a dataset with x, y, and value columns (note that this is case sensitive!) #It creates a chart area the size of the test area (multiplied by the grid size), based on the overall test area (i.e. it expands smaller sections to match the HCP collection) #It adds a heatmap and a contour chart cchart <- function(x, limits) { x %>% ggplot(aes(x=x*xgrid,y=y*ygrid))+ coord_fixed()+ expand_limits(x=c(minx*xgrid,maxx*xgrid),y=c(miny*ygrid,maxy*ygrid))+ geom_tile(aes(fill=value))+ stat_contour(aes(z=value), col="white", binwidth=bw) + scale_fill_gradient(low = lowcol, high = highcol, limits = limits) + xlab("x Position (mm)") + ylab("y Position (mm)") } #Run the Half Cell Potential chart cchart(chartdata$hcp, hcplimit) + ggtitle(paste0(substr(file,1,nchar(file)-4), ": Half Cell Potential")) + labs(fill="mV") #Run the Resistance chart cchart(chartdata$res, reslimit) + ggtitle(paste0(substr(file,1,nchar(file)-4), ": Resistance")) + labs(fill=expression(paste("k",Omega,sep=""))) #Run the Corrosion chart cchart(chartdata$corr, corrlimit) + ggtitle(paste0(substr(file,1,nchar(file)-4), ": Corrosion Rate"))+ labs(fill=expression(paste("uA/",cm^2,sep="")))
Baidu
map