2017-01-03 9 views
0

にスケールIはRでggplot2を使って化学元素をプロットするために、このスクリプトを使用しています:が同じスケールまたはログにそれらをTRUN ggplot

# Load the same Data set but in different name, becaus it is just for  plotting elements as a well log: 
Core31B1 <- read.csv('OilSandC31B1BatchResultsCr.csv', header = TRUE) 
# 
# Calculating the ratios of Ca.Ti, Ca.K, Ca.Fe: 
C31B1$Ca.Ti.ratio <- (C31B1$Ca/C31B1$Ti) 
C31B1$Ca.K.ratio <- (C31B1$Ca/C31B1$K) 
C31B1$Ca.Fe.ratio <- (C31B1$Ca/C31B1$Fe) 
C31B1$Fe.Ti.ratio <- (C31B1$Fe/C31B1$Ti) 
#C31B1$Si.Al.ratio <- (C31B1$Si/C31B1$Al) 
# 
# Create a subset of ratios and depth 
core31B1_ratio <- C31B1[-2:-18] 
# 
# Removing the totCount column: 
Core31B1 <- Core31B1[-9] 
# 
# Metling the data set based on the depth values, to have only three columns: depth, element and count 
C31B1_melted <- melt(Core31B1, id.vars="depth") 
#ratio melted 
C31B1_ra_melted <- melt(core31B1_ratio, id.vars="depth") 
# 
# Eliminating the NA data from the data set 
C31B1_melted<-na.exclude(C31B1_melted) 
# ratios 
C31B1_ra_melted <-na.exclude(C31B1_ra_melted) 
# 
# Rename the columns: 
colnames(C31B1_melted) <- c("depth","element","counts") 
# ratios 
colnames(C31B1_ra_melted) <- c("depth","ratio","percentage") 
# 
# Ploting the data in well logs format using ggplot2: 
Core31B1_Sp <- ggplot(C31B1_melted, aes(x=counts, y=depth)) + 
theme_bw() + 
geom_path(aes(linetype = element))+ geom_path(size = 0.6) + 
labs(title='Core 31 Box 1 Bioturbated sediments') + 
scale_y_reverse() + 
    facet_grid(. ~ element, scales='free_x') #rasterImage(Core31Image, 0, 1515.03, 150, 0, interpolate = FALSE) 
# 
# View the plot: 
Core31B1_Sp 

あなたが見ることができるように私には、以下の画像を(GOTプロットは7つの要素のプロットを持ち、それぞれがその規模を持つ陰影と一番左の画像)を無視してください:。

私の質問ですが、そこにあるログスケールを使用してのように同じこれらのスケールを作るための方法を?はいの場合は、スケールを変更するためにコードを変更する必要がありますか?

+0

をあなたは 'free_x'スケールを使用することにしましたか?どうした? – hrbrmstr

+0

スケールをLog scaleに変更して、同じになるようにしたいのですが、比較するのがはるかに簡単です! – Majed86

答えて

0

"同じもの"が意味するものは明確ではありません。なぜなら、それはログの値を変換するのと同じ結果をもたらさないからです。ここでは、ログの変換を取得する方法です。使用しない場合は、free_xを使用して、あなたが求めているプロットを与えます。

あなたは(良い質問をする方法の詳細についてhereを参照)任意の再現性のあるデータを提供しなかったことから、まず、ここで私はあなたのデータがあると思います機能の少なくとも一部を与えるものもあります。最後の行は比率のログベース2を取ること

forRatios <- 
    names(iris)[1:3] %>% 
    combn(2, paste, collapse = "/") 

toPlot <- 
    iris %>% 
    mutate_(.dots = forRatios) %>% 
    select(contains("/")) %>% 
    mutate(yLocation = 1:n()) %>% 
    gather(Comparison, Ratio, -yLocation) %>% 
    mutate(logRatio = log2(Ratio)) 

注:私は建設を行うためにtidyverse(特にdplyrtidyr)を使用しています。これにより、各方向の比(1を上回る、下回る)を有意義にプロットすることができます。私はそのステップがあなたが必要とするものだと思う。 dplyrを使用しない場合は、myDF$logRatio <- log2(myDF$ratio)と同様の処理を実行できます。

その後、あなたはちょうどそれをプロットすることができます

ggplot(
    toPlot 
    , aes(x = logRatio 
     , y = yLocation)) + 
    geom_path() + 
    facet_wrap(~Comparison) 

は与える:

enter image description here

関連する問題