2014-12-03 94 views
1

我有關於在R.如何改變同參數函數線條的顏色和寬度中的R

我想換的線的顏色和/或寬度在同參數的曲線圖票面功能問題功能。 (我正在使用par函數,因爲下面的gaps.plot命令不允許包含「col」選項。在synth命令之後會使用gaps.plot命令)。

所以,我用了下面的命令。但我注意到BOX的線條改變了,而不是GRAPHS的線條。

synth1<-read.csv(file="C:\\Users\\Research\\R\\synthinR_v4.csv",header=TRUE) 
attach(synth1) 
library("Synth") 

dataprep.out34 <- dataprep(foo = synth1, predictors = c("lncdsales", "md1", "md2","md3", "md4", "md5", "md6", "md7", "md8", "md9", "md10", "md11", "yd1", "yd2", "yd3", "yd4", "yd5", "yd6", "yd7", "yd8"), predictors.op = "mean", time.predictors.prior = -13:1, dependent = "lndigital", unit.variable = "artistalbumcode", time.variable = "release", treatment.identifier = 34, controls.identifier = c(1:33, 35:49), time.optimize.ssr = -13:1, time.plot = -13:25) 

synth.out34 <- synth(data.prep.obj = dataprep.out34, method = "BFGS") 

par(lwd = 2, col="#cccccc") 

gaps.plot(synth.res = synth.out34, dataprep.res = dataprep.out34, Ylab = " Log Digital Sales ", Xlab = "Release", Ylim = c(-7, 7) , Main = NA) 

有誰知道如何解決這個問題? 非常感謝您的幫助。我非常感謝!

+0

從哪個庫你吃的是'plot.gaps'功能?它不是基本的圖形... – Tim 2014-12-03 13:36:23

+0

標記爲遷移到SO,我們也沒有'synth1'請通過提供'dput(synth1)'輸出的數據集或者提供一個小的今日數據設置 – 2014-12-03 13:38:31

+0

非常感謝您的關注!是否可以在這個網站上附加一個csv文件? – 2014-12-03 13:46:32

回答

2

col參數par設置默認繪製顏色(即,當col未在繪製調用明確指定),但不幸的是col = "black"硬編碼到的gaps.plot源。

您可以通過(1)查看源代碼(F2在RStudio,或者只是執行gaps.plot),編輯它並將其分配給新的對象,或(2)做一些使函數的修改後的副本像下面這樣:

gaps.plot2 <- eval(parse(text=gsub('col = "black"', 'col = "red"', 
            deparse(Synth:::gaps.plot)))) 

,然後使用gaps.plot2,就像使用gaps.plot

gaps.plot2(synth.res = synth.out34, dataprep.res = dataprep.out34, 
      Ylab = " Log Digital Sales ", Xlab = "Release", Ylim = c(-7, 7) , 
      Main = NA) 

enter image description here

類似地改變lwd。例如,使線紅色,並有3個寬度,使用嵌套gsub電話這樣的:

gaps.plot2 <- eval(parse(text=gsub('lwd = 2', 'lwd = 3', 
            gsub('col = "black"', 'col = "red"', 
             deparse(Synth:::gaps.plot))))) 
+0

我不能夠感謝你! – Michael 2014-12-03 15:40:05