Re: [R] MSBVAR Package

2017-09-27 Thread Jim Lemon
Hi Ahmad,
I don't know of any, but this might help:

http://maths-people.anu.edu.au/~johnm/courses/r/ASC2008/pdf/Rtimeseries-ohp.pdf

Jim

On Thu, Sep 28, 2017 at 2:12 PM, ah a  wrote:
> Hi Jim
>
> Thank you very much for your reply and your help.
> By the way, where can I find some tutorial videos?
> Thanks again for your help.
>
> Best regards
> Ahmad
>

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] building random matrices from vectors of random parameters

2017-09-27 Thread Peter Langfelder
I would try something like

n = 5
a <- rnorm(n,0.8,0.1)
so <- rnorm(n,0.5,0.1)
m <- rnorm(n,1.2,0.1)
mats = mapply(function(sa1, so1, m1) matrix(c(0,sa1*m1,so1,sa1),2,2,byrow=T),
   a, so, m, SIMPLIFY = FALSE)

> mats
[[1]]
  [,1]  [,2]
[1,] 0.000 0.9129962
[2,] 0.4963598 0.7067311

[[2]]
  [,1]  [,2]
[1,] 0.000 1.0150316
[2,] 0.5489887 0.8469046

[[3]]
  [,1]  [,2]
[1,] 0.000 0.9516137
[2,] 0.3724521 0.8306535

[[4]]
  [,1]  [,2]
[1,] 0.000 1.0525355
[2,] 0.8075108 0.8314638

[[5]]
  [,1]  [,2]
[1,] 0.000 0.9400074
[2,] 0.4803386 0.7901753

On Wed, Sep 27, 2017 at 5:47 PM, Evan Cooch  wrote:
> Suppose I have interest in a matrix with the following symbolic structure
> (specified by 3 parameters: sa, so, m):
>
> matrix(c(0,sa*m,so,sa),2,2,byrow=T)
>
> What I can't figure out is how to construct a series of matrices, where the
> elements/parameters are rnorm values. I'd like to construct separate
> matrices, with each matrix in the series using the 'next random parameter
> value'. While the following works (for generating, say, 5 such random
> matrices)
>
> replicate(5,matrix(c(0,rnorm(1,0.8,0.1)*rnorm(1,1.2,0.1),rnorm(1,0.5,0.1),rnorm(1,0.8,0.1)),2,2,byrow=T))
>
> its inelegant, and a real pain if the matrix gets large (say, 20 x 20).
>
> I'm wondering if there is an easier way. I tried
>
>> sa <- rnorm(5,0.8,0.1)
>> so <- rnorm(5,0.5,0.1)
>> m <- rnorm(5,1.2,0.1)
>
> matrix(c(0,sa*m,so,sa),2,2,byrow=T)
>
> but that only returns a single matrix, not 5 matrices as I'd like. I also
> tried several variants of the 'replicate' approach (above), but didn't
> stumble across anything that seemed to work.
>
> So, is there a better way than something like:
>
> replicate(5,matrix(c(0,rnorm(1,0.8,0.1)*rnorm(1,1.2,0.1),rnorm(1,0.5,0.1),rnorm(1,0.8,0.1)),2,2,byrow=T))
>
> Many thanks in advance...
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] building random matrices from vectors of random parameters

2017-09-27 Thread Evan Cooch
Suppose I have interest in a matrix with the following symbolic 
structure (specified by 3 parameters: sa, so, m):


matrix(c(0,sa*m,so,sa),2,2,byrow=T)

What I can't figure out is how to construct a series of matrices, where 
the elements/parameters are rnorm values. I'd like to construct separate 
matrices, with each matrix in the series using the 'next random 
parameter value'. While the following works (for generating, say, 5 such 
random matrices)


replicate(5,matrix(c(0,rnorm(1,0.8,0.1)*rnorm(1,1.2,0.1),rnorm(1,0.5,0.1),rnorm(1,0.8,0.1)),2,2,byrow=T))

its inelegant, and a real pain if the matrix gets large (say, 20 x 20).

I'm wondering if there is an easier way. I tried

> sa <- rnorm(5,0.8,0.1)
> so <- rnorm(5,0.5,0.1)
> m <- rnorm(5,1.2,0.1)

matrix(c(0,sa*m,so,sa),2,2,byrow=T)

but that only returns a single matrix, not 5 matrices as I'd like. I 
also tried several variants of the 'replicate' approach (above), but 
didn't stumble across anything that seemed to work.


So, is there a better way than something like:

replicate(5,matrix(c(0,rnorm(1,0.8,0.1)*rnorm(1,1.2,0.1),rnorm(1,0.5,0.1),rnorm(1,0.8,0.1)),2,2,byrow=T))

Many thanks in advance...

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] build a SpatialLines object from a list

2017-09-27 Thread MacQueen, Don
Have you tried following the example in

  ?'SpatialLines-class'

You'll probably get better help from R-sig-geo

And please don't send html email, it makes your email hard to read.

--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
Lab cell 925-724-7509
 
 

On 9/26/17, 2:36 AM, "R-help on behalf of Ashraf Afana via R-help" 
 wrote:

Hi Eric,

Thanks for the help.But this will not solve the problem as it will generate 
a list and what I need is an object of class sp using SpatialLine function from 
sp package.So, I need to convert each matrix to coordinates and then to a line 
and then to a spatial line as figured in the code.

My data structure is a list of 141 matrices.Each matrix represents 
coordinates of the river lines position.

Ashraf, cheers 

On Monday, 25 September 2017, 16:56, Eric Berger 
 wrote:
 

 Hi Ashraf,It is not obvious to me what your structures are but one problem 
in your function is the assignment tt1 <- SpatialLines(list(tt[[i]])).
This will set tt1 to just have one item.
Consider the following
test.func <- function(x) {tt1 <- list()for ( i in ... )  {   
...   tt1[[i]] <- SpatialLines(tt[[i]])}return(tt1)}

HTH,Eric
On Mon, Sep 25, 2017 at 3:40 PM, Ashraf Afana via R-help 
 wrote:

Hi all,I'm trying to build a SpatialLines object from a list that contains 
124 river segments. Each segment in the list contains the x,y coordinates. I'm 
using the following code to create the SpatialLines object, but it just 
retrieves one segment. Any suggestions?

test.func = function(x){
 for (i in 1:length(x)) {tt[[i]] <- x[i]; tt[[i]]  = 
Line(tt[[i]]); tt[[i]]  = Lines(list(tt[[i]] ), 'i')tt1 = 
SpatialLines(list(tt[[i]]))   }return(tt1)  }
Ashraf,
[[alternative HTML version deleted]]

__ 
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/ listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/ 
posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



   
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] need held in r coding.

2017-09-27 Thread MacQueen, Don
It's pretty clear from the error message that dat$Date is not an appropriate 
time-based object.

Since dat$Date is created by the get_majorlandmarks() function, and your 
question provides no information about that, it's hard to be more specific.

However, I would suggest looking at the output of
  class(dat$Date)
and
  str(dat$Date)
The results should indicate that dat$Date somehow indicates a time-based 
ordering. 

I wouldn't be surprised if dat$Date is a factor (the class() function will tell 
you if it is), in which case something is wrong with how dat is constructed. 
For example, there might be invalid values in an input file.

The other thing is whether dates are acceptable to xts() for the order.by 
argument. I don't know.

-Don

--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
Lab cell 925-724-7509
 
 

On 9/27/17, 2:31 PM, "R-help on behalf of istiyak ahamad" 
 wrote:

Need Help in Debugging below script:



dat <- get_majorlandmarks(dat,Dmin,Per)
fit_xts <- xts(dat$fit,order.by = dat$Date,frequency = 365)
close_xts <- xts(dat$Close, order.by = dat$Date, frequency = 365 )
majorlandmarks_xts <-xts(dat$Close[dat$majorlandmarks==TRUE], order.by =
dat$Date[dat$majorlandmarks==TRUE], frequency = 365 )
minorlandmarks_xts <-  xts(dat$Close[dat$minorlandmarks==TRUE], order.by =
dat$Date[dat$minorlandmarks==TRUE], frequency = 365 )
landmarkschart_data <-
cbind(close_xts,fit_xts,majorlandmarks_xts,minorlandmarks_xts)



Error:- order.by requires an appropriate time-based object

dygraphs::dygraph(landmarkschart_data, xlab = "Time",ylab = "Price") %>%
  dySeries("..1",label = "Close", drawPoints = FALSE,  strokeWidth = 1,
color = "black") %>%
  dySeries("..2",label = "Fit", drawPoints = FALSE,  strokeWidth = 1, color
= "red") %>%
  dySeries("..3",label = "Major LandMarks", drawPoints = TRUE, pointSize =
5, strokeWidth = 0, color = "darkorange") %>%
  dySeries("..4",label = "Minor LandMarks", drawPoints = TRUE, pointSize =
1, strokeWidth = 0, color = "darkblue") %>%
  dyRangeSelector()
###Estimating error with different parameters
# RMSE <- vector()
# for(i in seq(0.01,0.1,0.01)){
#   dat <- get_majorlandmarks(dat,i,0.01)
#   RMSE[i] <- sqrt(sum((dat$fit-dat$Close)^2)/nrow(dat))
# }
# plot(RMSE)

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] MSBVAR Package

2017-09-27 Thread Jim Lemon
Hi Ahmed,
You seem to know about the package, so I would suggest downloading:

https://cran.r-project.org/web/packages/MSBVAR/MSBVAR.pdf

getting a big cup of coffee and going through the examples to see how
the package works. If you can't make any sense out of that, you will
probably have to contact someone who does know how to use the package
and is willing to provide a tutorial (that is not me).

Jim

On Wed, Sep 27, 2017 at 5:22 PM, ah a via R-help  wrote:
> dear sirs or madam,
>
> As I'm interested to search about the monetary transmission channel in our
> country by MSVAR model, I would be grateful if you help me and tell me how
> can I run MSVAR in R or send me the related code to run this model .
> Actually, I'm new user of R and I don't know how to run Markov Switching
> Var Model in R.
>
> Thank you very much in advance for your help.
>
> Best Regards,
> Ahmad Arabian
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] need held in r coding.

2017-09-27 Thread istiyak ahamad
Need Help in Debugging below script:



dat <- get_majorlandmarks(dat,Dmin,Per)
fit_xts <- xts(dat$fit,order.by = dat$Date,frequency = 365)
close_xts <- xts(dat$Close, order.by = dat$Date, frequency = 365 )
majorlandmarks_xts <-xts(dat$Close[dat$majorlandmarks==TRUE], order.by =
dat$Date[dat$majorlandmarks==TRUE], frequency = 365 )
minorlandmarks_xts <-  xts(dat$Close[dat$minorlandmarks==TRUE], order.by =
dat$Date[dat$minorlandmarks==TRUE], frequency = 365 )
landmarkschart_data <-
cbind(close_xts,fit_xts,majorlandmarks_xts,minorlandmarks_xts)



Error:- order.by requires an appropriate time-based object

dygraphs::dygraph(landmarkschart_data, xlab = "Time",ylab = "Price") %>%
  dySeries("..1",label = "Close", drawPoints = FALSE,  strokeWidth = 1,
color = "black") %>%
  dySeries("..2",label = "Fit", drawPoints = FALSE,  strokeWidth = 1, color
= "red") %>%
  dySeries("..3",label = "Major LandMarks", drawPoints = TRUE, pointSize =
5, strokeWidth = 0, color = "darkorange") %>%
  dySeries("..4",label = "Minor LandMarks", drawPoints = TRUE, pointSize =
1, strokeWidth = 0, color = "darkblue") %>%
  dyRangeSelector()
###Estimating error with different parameters
# RMSE <- vector()
# for(i in seq(0.01,0.1,0.01)){
#   dat <- get_majorlandmarks(dat,i,0.01)
#   RMSE[i] <- sqrt(sum((dat$fit-dat$Close)^2)/nrow(dat))
# }
# plot(RMSE)

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Need Help in Debugging

2017-09-27 Thread istiyak ahamad
I am getting following error when running this script :Error in
length(runsum) : object 'runsum' not found


##error function
dat$fit <- NULL
dat$fit[dat$majorlandmarks] <- dat$Close[dat$majorlandmarks]
run <- rle(dat$majorlandmarks)
runvalue <- run$values
runsum <- cumsum(run$lengths)
run <- run$lengths
for(i in 1:(length(runsum)-1)){
  if (runvalue[i]==FALSE){
left <- runsum[i-1]
right <- runsum[i+1]-(run[i+1]-1)

slope <- (dat$Close[dat$seq==right]-dat$Close[dat$seq==left])/(run[i]+1)
dat$fit[(left+1):(right-1)] <- seq(1:run[i])*slope+dat$Close[left]

  }
return(dat)
}

Error in length(runsum) : object 'runsum' not found


Error in length(runsum) : object 'runsum' not found

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [ESS] R window: Text is read only

2017-09-27 Thread Vitalie Spinu


If you activate the debugger (M-x toggle-debug-on-error), does it show anything
meaningful?

>> On Wed, Sep 27 2017 09:47, Christian wrote:

> Hi, after start with M-x R the R window behaves OK, allowing writing to. BUT,
> after navigating in the help system, R refuses writing with "Text is read
> only". This makes R unusable. I found no help on the net, so, please, give me
> some hints.
> This behaviour started bothering me out of the blue. Some mis-manipulation?

> TIA  C.

__
ESS-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/ess-help


[R] MSBVAR Package

2017-09-27 Thread ah a via R-help
dear sirs or madam,

As I'm interested to search about the monetary transmission channel in our
country by MSVAR model, I would be grateful if you help me and tell me how
can I run MSVAR in R or send me the related code to run this model .
Actually, I'm new user of R and I don't know how to run Markov Switching
Var Model in R.

Thank you very much in advance for your help.

Best Regards,
Ahmad Arabian

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[ESS] R window: Text is read only

2017-09-27 Thread Christian
Hi, after start with M-x R the R window behaves OK, allowing writing to. 
BUT, after navigating in the help system, R refuses writing with "Text 
is read only". This makes R unusable. I found no help on the net, so, 
please, give me some hints.

This behaviour started bothering me out of the blue. Some mis-manipulation?

TIA  C.
--
Christian Hoffmann
Rigiblickstrasse 15b
CH-8915 Hausen am Albis
Switzerland
Telefon +41-(0)44-7640853

__
ESS-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/ess-help


Re: [R] disturbed legend in ggplot2

2017-09-27 Thread Troels Ring

Hi Ulrik - thanks a lot for pointing out this blunder - now it is fine!

Best wishes

Troels


Den 27-09-2017 kl. 09:31 skrev Ulrik Stervbo:

Hi Troels,

Try to move the size argument out of the aesthetic.

Best wishes,
Ulrik

On Mi., 27. Sep. 2017, 08:51 Troels Ring  wrote:


Dear friends - below is a subset of a much larger material showing two
ways of generating two "lines". The intention is to have the colour
reflect a variable, pH, but the legend is disturbed. The little part
marked "3" above the colour scale is unwelcome. Why did it appear? How
could I avoid it?

I'm on Windows 7, R version 3.4.1 (2017-06-30) -- "Single Candle"

All best wishes

Troels Ring
Aalborg, Denmark

library(ggplot2)
DF1 <-
structure(list(P = c(0, 0.00222, 0.00444,
0.00667, 0.00889, 0.0111,
0.0133, 0.0156, 0.0178, 0.02,
0, 0.00222, 0.00444, 0.00667,
0.00889, 0.0111, 0.0133,
0.0156, 0.0178, 0.02), pH = c(12.3979595548431,
12.3129161148613, 12.2070984076445, 12.0669463736967, 11.8586790792785,
11.4437319273717, 7.64497330556925, 6.98905682614207, 6.63520883742788,
6.3229313658492, 12.176061323132, 12.0234712172719, 11.7861230637902,
11.2219147985144, 7.14240749824074, 6.53119941380901, 5.95522932117427,
3.25184520894594, 2.55614400932465, 2.30097494287507), BC =
c(0.0576574111386315,
0.047331331067055, 0.037206026657832, 0.0268607893098731,
0.0166183791472022,
0.00639593998967551, 0.0033597279094, 0.00854377959176608,
0.00987464693654883, 0.00863636089604445, 0.0343718830720469,
0.0242985554593397, 0.0140710602077036, 0.00383913993097999,
0.00439784065436743, 0.00582135949288444, 0.00336240952299985,
0.00129948001017736, 0.00640073762860721, 0.0115158433720248),
  SID = c(25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 15, 15, 15,
  15, 15, 15, 15, 15, 15, 15)), .Names = c("P", "pH", "BC",
"SID"), row.names = c(NA, -20L), class = "data.frame")

df1 <- subset(DF1,SID==25)
df2 <- subset(DF1,SID==15)
v <- ggplot()
v <- v + geom_line(data=df1, aes(x=P, y=BC,col=pH,size=3))
v1 <- v + geom_line(data=df2, aes(x=P, y=BC,col=pH,size=3))

v <- ggplot()
v <- v + geom_line(data=DF1, aes(x=P, y=BC,group=SID,col=pH,size=3))

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] disturbed legend in ggplot2

2017-09-27 Thread Ulrik Stervbo
Hi Troels,

Try to move the size argument out of the aesthetic.

Best wishes,
Ulrik

On Mi., 27. Sep. 2017, 08:51 Troels Ring  wrote:

> Dear friends - below is a subset of a much larger material showing two
> ways of generating two "lines". The intention is to have the colour
> reflect a variable, pH, but the legend is disturbed. The little part
> marked "3" above the colour scale is unwelcome. Why did it appear? How
> could I avoid it?
>
> I'm on Windows 7, R version 3.4.1 (2017-06-30) -- "Single Candle"
>
> All best wishes
>
> Troels Ring
> Aalborg, Denmark
>
> library(ggplot2)
> DF1 <-
> structure(list(P = c(0, 0.00222, 0.00444,
> 0.00667, 0.00889, 0.0111,
> 0.0133, 0.0156, 0.0178, 0.02,
> 0, 0.00222, 0.00444, 0.00667,
> 0.00889, 0.0111, 0.0133,
> 0.0156, 0.0178, 0.02), pH = c(12.3979595548431,
> 12.3129161148613, 12.2070984076445, 12.0669463736967, 11.8586790792785,
> 11.4437319273717, 7.64497330556925, 6.98905682614207, 6.63520883742788,
> 6.3229313658492, 12.176061323132, 12.0234712172719, 11.7861230637902,
> 11.2219147985144, 7.14240749824074, 6.53119941380901, 5.95522932117427,
> 3.25184520894594, 2.55614400932465, 2.30097494287507), BC =
> c(0.0576574111386315,
> 0.047331331067055, 0.037206026657832, 0.0268607893098731,
> 0.0166183791472022,
> 0.00639593998967551, 0.0033597279094, 0.00854377959176608,
> 0.00987464693654883, 0.00863636089604445, 0.0343718830720469,
> 0.0242985554593397, 0.0140710602077036, 0.00383913993097999,
> 0.00439784065436743, 0.00582135949288444, 0.00336240952299985,
> 0.00129948001017736, 0.00640073762860721, 0.0115158433720248),
>  SID = c(25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 15, 15, 15,
>  15, 15, 15, 15, 15, 15, 15)), .Names = c("P", "pH", "BC",
> "SID"), row.names = c(NA, -20L), class = "data.frame")
>
> df1 <- subset(DF1,SID==25)
> df2 <- subset(DF1,SID==15)
> v <- ggplot()
> v <- v + geom_line(data=df1, aes(x=P, y=BC,col=pH,size=3))
> v1 <- v + geom_line(data=df2, aes(x=P, y=BC,col=pH,size=3))
>
> v <- ggplot()
> v <- v + geom_line(data=DF1, aes(x=P, y=BC,group=SID,col=pH,size=3))
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] disturbed legend in ggplot2

2017-09-27 Thread Troels Ring
Dear friends - below is a subset of a much larger material showing two 
ways of generating two "lines". The intention is to have the colour 
reflect a variable, pH, but the legend is disturbed. The little part 
marked "3" above the colour scale is unwelcome. Why did it appear? How 
could I avoid it?


I'm on Windows 7, R version 3.4.1 (2017-06-30) -- "Single Candle"

All best wishes

Troels Ring
Aalborg, Denmark

library(ggplot2)
DF1 <-
structure(list(P = c(0, 0.00222, 0.00444,
0.00667, 0.00889, 0.0111,
0.0133, 0.0156, 0.0178, 0.02,
0, 0.00222, 0.00444, 0.00667,
0.00889, 0.0111, 0.0133,
0.0156, 0.0178, 0.02), pH = c(12.3979595548431,
12.3129161148613, 12.2070984076445, 12.0669463736967, 11.8586790792785,
11.4437319273717, 7.64497330556925, 6.98905682614207, 6.63520883742788,
6.3229313658492, 12.176061323132, 12.0234712172719, 11.7861230637902,
11.2219147985144, 7.14240749824074, 6.53119941380901, 5.95522932117427,
3.25184520894594, 2.55614400932465, 2.30097494287507), BC = 
c(0.0576574111386315,
0.047331331067055, 0.037206026657832, 0.0268607893098731, 
0.0166183791472022,

0.00639593998967551, 0.0033597279094, 0.00854377959176608,
0.00987464693654883, 0.00863636089604445, 0.0343718830720469,
0.0242985554593397, 0.0140710602077036, 0.00383913993097999,
0.00439784065436743, 0.00582135949288444, 0.00336240952299985,
0.00129948001017736, 0.00640073762860721, 0.0115158433720248),
SID = c(25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 15, 15, 15,
15, 15, 15, 15, 15, 15, 15)), .Names = c("P", "pH", "BC",
"SID"), row.names = c(NA, -20L), class = "data.frame")

df1 <- subset(DF1,SID==25)
df2 <- subset(DF1,SID==15)
v <- ggplot()
v <- v + geom_line(data=df1, aes(x=P, y=BC,col=pH,size=3))
v1 <- v + geom_line(data=df2, aes(x=P, y=BC,col=pH,size=3))

v <- ggplot()
v <- v + geom_line(data=DF1, aes(x=P, y=BC,group=SID,col=pH,size=3))

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.