[R] Some help understanding ggplot2

2015-11-28 Thread Glenn Schultz

All,

I am trying to format a graph using scales and percent format but I am missing 
something and all my graphics books on ggplot2 are now quite far behind where 
ggplot2 is today.    I seem to be missing a trick but the documentation implies 
that percent_format() will multiply by 100 and add %.  I think the problem has 
to do with normalizing the data.

Glenn


Here is my data
structure(list(Rate = c(0.004975, 0.0126625, 0.0180375, 0.0136, 
0.016, 0.0196, 0.023, 0.0256, 0.0293, 0.0324, 0.0338), Maturity = c(0.0833, 
0.25, 0.5, 1, 2, 3, 4, 5, 7, 10, 30)), .Names = c("Rate", "Maturity"
), row.names = c("ED1M", "ED3M", "ED6M", "USSW1", "USSW2", "USSW3", 
"USSW4", "USSW5", "USSW7", "USSW10", "USSW30"), class = "data.frame")


data <- data.frame(Rates[1:2,2:12])
data <- data.frame(t(data))
Note: if I do not normalize the data by dividing by 100 percent_format() works 
but then 2.25% is 225%
data[,1] <- data[,1]/100
colnames(data) <- c("Rate", "Maturity")


Here is the color palette
cbbPalette <- c("#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7", 
"#00","#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7", "#00")



This code does not work and returns an error
ggplot(data, aes(x=Maturity, y = Rate, colour = 'Rate')) +
geom_line(size = 1.5) +
theme_minimal()+
theme(panel.grid.major = element_line(size = .25, color = "grey")) +
scale_y_continuous(breaks = c(seq(0, 0.05, .0025)), percent_format()) +
scale_x_continuous(breaks = c(0, 1, 2, 3, 4, 5, 7, 10, 30)) +
ylab("Swap Rate (%)") +
xlab("Maturity") +
theme(axis.text.y = element_text(size = 15)) +
theme(axis.text.x = element_text(angle = 0, size = 15)) +
theme(axis.title = element_text(size = 20)) +
scale_colour_manual(values = cbbPalette, guide = FALSE)

This code works but no percent
ggplot(data, aes(x=Maturity, y = Rate, colour = 'Rate')) +
geom_line(size = 1.5) +
theme_minimal()+
theme(panel.grid.major = element_line(size = .25, color = "grey")) +
scale_y_continuous(breaks = c(seq(0, 0.05, .0025))) +
scale_x_continuous(breaks = c(0, 1, 2, 3, 4, 5, 7, 10, 30)) +
ylab("Swap Rate (%)") +
xlab("Maturity") +
theme(axis.text.y = element_text(size = 15)) +
theme(axis.text.x = element_text(angle = 0, size = 15)) +
theme(axis.title = element_text(size = 20)) +
scale_colour_manual(values = cbbPalette, guide = FALSE)
__
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] some help

2012-11-29 Thread PIKAL Petr
Hi

Maybe you could use  stack(dat) or melt(dat) from reshape package.

Regards
Petr

> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of dattel_palme
> Sent: Monday, November 26, 2012 12:13 PM
> To: r-help@r-project.org
> Subject: Re: [R] some help
> 
> Hey again!
> 
> I finally, after some work done before, had time to apply the code.
> The sorting of the table did not work well or maybe something was
> misunderstood.
> 
> I have a table with 973 rows and 1329 col (ascii/text file). I want to
> sort the table that all columns are one under each other so that at the
> end I have 973*1329 rows and 1 col. The col should be sorted in a way
> that col 2 is under col 1, col 3 under col 2, col 4 under col 3 etc.
> 
> I applied this code:
> dat <- read.table(filename, sep=, header=TRUE) stacked <-
> do.call(rbind, dat)
> unlist(dat)
> 
> ..but putting dim(dat), the number of rows and col was still 973 and
> 1329.
> So seemingly it did not work as i wanted.
> 
> Thanks very much for more help.
> 
> Stefan
> 
> 
> 
> 
> 
> 
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/some-help-
> tp4648316p4650828.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> 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
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] some help

2012-11-26 Thread jim holtman
try this:  (provide sample data next time)

> # create some test data
> x <- data.frame(LST = runif(1000), NDVI = runif(1000, 0, 1))
> head(x,10)  # show some data
  LST   NDVI
1  0.86542839 0.95129647
2  0.88910058 0.75971649
3  0.44086718 0.86532140
4  0.99879370 0.05511501
5  0.02401490 0.92282834
6  0.56026534 0.80915721
7  0.65051596 0.03606430
8  0.25897388 0.61624609
9  0.07873261 0.85179368
10 0.09829056 0.91198307
> # create partition values
> partition <- seq(0, 1, .01)
> # add column to the data to define the partition
> x$part <- cut(x$NDVI, partition)
> head(x)
LST   NDVIpart
1 0.8654284 0.95129647 (0.95,0.96]
2 0.8891006 0.75971649 (0.75,0.76]
3 0.4408672 0.86532140 (0.86,0.87]
4 0.9987937 0.05511501 (0.05,0.06]
5 0.0240149 0.92282834 (0.92,0.93]
6 0.5602653 0.80915721  (0.8,0.81]
> # now compute range (min/mx) for the data
> xRange <- tapply(x$LST, x$part, range)
> head(xRange, 10)
$`(0,0.01]`
[1] 0.01945995 0.83500402

$`(0.01,0.02]`
[1] 0.02267906 0.69770971

$`(0.02,0.03]`
[1] 0.01287795 0.75275416

$`(0.03,0.04]`
[1] 0.1402162 0.9960408

$`(0.04,0.05]`
[1] 0.007688249 0.691519845

$`(0.05,0.06]`
[1] 0.1047314 0.9987937

$`(0.06,0.07]`
[1] 0.002181767 0.990990999

$`(0.07,0.08]`
[1] 0.08271319 0.87609409

$`(0.08,0.09]`
[1] 0.1174585 0.8931750

$`(0.09,0.1]`
[1] 0.2331289 0.8485212



On Mon, Nov 26, 2012 at 9:56 AM, dattel_palme  wrote:
> Hey
>
> The code need some corrections and I would kindly ask for help.
>
> Say:
> I have a table with two columns:
> col1=LST and col2=NDVI
> i would like to sort all data by NDVI.
> in reality the NDVI ranges between 0 and 1 (although some values might be
> minus also).
> I want to sort by NDVI values and then make 100 intervals of 0.01 ndvi.
> therefore the first inerval is 0.01-0.02, the second 0.02-0.03 and so on..
> for each interval I would like to get the highest (max) and lowest (min)
> value of LST.
> It would be very helpful if this values can be written in a seperate
> table/file.
>
> Thanks you very much for help!
> Stefan
>
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/some-help-tp4648316p4650844.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> 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.



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

__
R-help@r-project.org mailing list
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] some help

2012-11-26 Thread dattel_palme
Hey

The code need some corrections and I would kindly ask for help.

Say:
I have a table with two columns:
col1=LST and col2=NDVI
i would like to sort all data by NDVI. 
in reality the NDVI ranges between 0 and 1 (although some values might be
minus also).
I want to sort by NDVI values and then make 100 intervals of 0.01 ndvi.
therefore the first inerval is 0.01-0.02, the second 0.02-0.03 and so on..
for each interval I would like to get the highest (max) and lowest (min)
value of LST. 
It would be very helpful if this values can be written in a seperate
table/file. 

Thanks you very much for help!
Stefan



--
View this message in context: 
http://r.789695.n4.nabble.com/some-help-tp4648316p4650844.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
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] some help

2012-11-26 Thread dattel_palme
Hey again!

I finally, after some work done before, had time to apply the code. 
The sorting of the table did not work well or maybe something was
misunderstood.

I have a table with 973 rows and 1329 col (ascii/text file). I want to sort
the table that all columns are one under each other so that at the end I
have 973*1329 rows and 1 col. The col should be sorted in a way that col 2
is under col 1, col 3 under col 2, col 4 under col 3 etc. 

I applied this code:
dat <- read.table(filename, sep=, header=TRUE)
stacked <- do.call(rbind, dat) 
unlist(dat) 

..but putting dim(dat), the number of rows and col was still 973 and 1329.
So seemingly it did not work as i wanted.

Thanks very much for more help.

Stefan







--
View this message in context: 
http://r.789695.n4.nabble.com/some-help-tp4648316p4650828.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
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] some help

2012-11-04 Thread dattel_palme
HI David,

Thanks for your answers,
I can't provide data here, but I can explain more:

It's satellite images as a text file (ascii). Two different images with two
different variables, land surface temperature (LST -lstascii =filename) and
an vegetation index (NDVI - ndviascii = filename).

The aim was to do a scatter plot of NDVI against LST, whereas the NDVI
should be on the x-axis. - The scatter plot itself is not needed as you will
see.

As I cannot compare each value (pixel value) in one image to the respective
value in the other image, i had the idea to sort all columns one under each
other. In the end I would have one column of one variable. I wanted to put
the two variables LST and NDVI together in one table, so that I have two
columns with two variables, and the value of one variable (NDVI) in each row
can be compared directly to the value of the other variable (LST) in the
same row. Why that? I wanted to sort the columns by the NDVI variable and
make 0,01 NDVI intervals. From each of these intervals I wanted to know the
max and min LST. These values I need for the regression - see the graph in
the file attached.

I this more clear now?

Attached you can see the regression line I need to find. For this I
developed this process (because I cannot compare pixel value by pixel value
in a multi column and row table). 

 

Best Regards
Stefan



--
View this message in context: 
http://r.789695.n4.nabble.com/some-help-tp4648316p4648410.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
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] some help

2012-11-04 Thread Rui Barradas

Hello,

Why answer to just me? You should keep it in the R-Help list, the odds 
of getting more (and hopefully better) answers is bigger.


Anyway, with data examples it's much easier to do something. I hope the 
code is self explanatory, except maybe for the use of scan(), not 
read.table. scan() reads in vectors, so there's no need to stack the 
columns anymore, they're just one big vector. Another thing is that 
around half of the values are zeros, and those don't show up in the 
graph you've posted, so I've filtered them out.


fdir <- "Asciis"  # change if needed
curr_dir <- setwd(fdir)  # save current directory and set working dir
fls <- list.files()
lst <- scan(fls[1], dec=",")
ndv <- scan(fls[2], dec=",")

str(lst)
str(ndv)

i0 <- ndv > 0 & lst > 0
ndv0 <- ndv[i0]
lst0 <- lst[i0]

brks <- seq(0, 1, by = 0.01)
group <- cut(ndv0, breaks = brks)

mins <- tapply(lst0, group, FUN = min) # one min per group
maxs <- tapply(lst0, group, FUN = max) # one max per group

fit.min <- lm(mins~brks[-1L])
fit.max <- lm(maxs~brks[-1L])

dev.new()
plot(ndv0, lst0, pch=".")
abline(fit.min, col = "blue")
abline(fit.max, col = "red")

#  Now with ave(). It returns one min/max per element in lst0,
#  so you'll have a vector as long as the original lst0, with the 
min/max

#  corresponding values.

mins2 <- ave(lst0, group, FUN = min)  # one min per element of lst0
maxs2 <- ave(lst0, group, FUN = max)  # one max per element of lst0

fit.min2 <- lm(mins2~ndv0)
fit.max2 <- lm(maxs2~ndv0)

dev.new()
plot(ndv0, lst0, pch=".")
abline(fit.min2, col = "blue")
abline(fit.max2, col = "red")


Hope this helps,

Rui Barradas
Em 04-11-2012 10:36, Stefan Mühlbauer escreveu:

Hello Rui,

Thanks a lot for your answer.
I can also provide you some data:

It's satellite images as a text file (ascii). Two different images with two 
different variables, land surface temperature (LST -lstascii =filename) and an 
vegetation index (NDVI - ndviascii = filename).
The aim was to do a scatter plot of NDVI against LST, whereas the NDVI should 
be on the x-axis. - The scatter plot itself is not needed as you will see.

As I cannot compare each value (pixel value) in one image to the respective 
value in the other image, i had the idea to sort all columns one under each 
other. In the end I would have one column of one variable. I wanted to put the 
two variables LST and NDVI together in one table, so that I have two columns 
with two variables, and the value of one variable (NDVI) in each row can be 
compared directly to the value of the other variable (LST) in the same row. Why 
that? I wanted to sort the columns by the NDVI variable and make 0,01 NDVI 
intervals. From each of these intervals I wanted to know the max and min LST. 
These values I need for the regression - see the graph in the file attached.


Can you understand this?
Aattached you can see the ascii files of LST and NDVI.

Again thanks a lot for help!

Best Regards

Stefan


  



Dipl.-Ing. Stefan Mühlbauer

Kaiser Strasse 85/2/15
A - 1070 Wien

E-Mail:
stefan.mue...@yahoo.de
dattel_pa...@yahoo.de




  Von: Rui Barradas 
An: dattel_palme 
CC: r-help@r-project.org
Gesendet: 19:34 Samstag, 3.November 2012
Betreff: Re: [R] some help
  
Hello,


Without data it's not easy to answer to your questions, but

1. Use ?unlist. If the data is in a file, read it with ?read.table and
the unlist the result. All columns will be stacked.

dat <- read.table(filename, ...)
unlist(dat)

2. At best confusing. But to divide a vector into groups use ?cut or
?findInterval and then, to find the maximum and minimum of each group,
?tapply or ?ave.

3. Regress what on what?


Provide a data example using dput for better answers:

dput( head(mydata, 30) )  # paste the output of this in a post


Hope this helps,

Rui Barradas
Em 03-11-2012 16:07, dattel_palme escreveu:

Hi People!

I have following concern consisting of some steps to do in R:

I have an ascii file (table) consisting of many columns and rows.
1. I would like to order all values of the columns one under each other. It
will begin with column 1, then column 2 under column 1, column 3 under
column 2 etc. until at the end there is only 1 column. How do I do it?

2. Second problem is to make a scatterplot of two variables (I think after
further explanation scatter plot itself will not be needed). I have two
columns of two different variables (that I produces before), column 1 with
variable 1 and column 2 with variable 2. I would like to order them by one
variable and 0,01 interval (the varibale values will range between 0 and 1).
>From each 0,01 interval (100 intervals) i want to pick the maximum and
minimum value of variable 2.

3. From the obtained ma

Re: [R] some help

2012-11-04 Thread dattel_palme
HI everybody,

Thanks for your answers,
I can't provide data here, but I can explain more: 

It's satellite images as a text file (ascii). Two different images with two
different variables, land surface temperature (LST -lstascii =filename) and
an vegetation index (NDVI - ndviascii = filename).

The aim was to do a scatter plot of NDVI against LST, whereas the NDVI
should be on the x-axis. - The scatter plot itself is not needed as you will
see.

As I cannot compare each value (pixel value) in one image to the respective
value in the other image, i had the idea to sort all columns one under each
other. In the end I would have one column of one variable. I wanted to put
the two variables LST and NDVI together in one table, so that I have two
columns with two variables, and the value of one variable (NDVI) in each row
can be compared directly to the value of the other variable (LST) in the
same row. Why that? I wanted to sort the columns by the NDVI variable and
make 0,01 NDVI intervals. From each of these intervals I wanted to know the
max and min LST. These values I need for the regression - see the graph in
the file attached.

I this more clear now?

Attached you can see the regression line I need to find. For this I
developed this process (because I cannot compare pixel value by pixel value
in a multi column and row table). 
 

Best Regards



--
View this message in context: 
http://r.789695.n4.nabble.com/some-help-tp4648316p4648382.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
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] some help

2012-11-03 Thread Rui Barradas

Hello,

Without data it's not easy to answer to your questions, but

1. Use ?unlist. If the data is in a file, read it with ?read.table and 
the unlist the result. All columns will be stacked.


dat <- read.table(filename, ...)
unlist(dat)

2. At best confusing. But to divide a vector into groups use ?cut or 
?findInterval and then, to find the maximum and minimum of each group, 
?tapply or ?ave.


3. Regress what on what?


Provide a data example using dput for better answers:

dput( head(mydata, 30) )  # paste the output of this in a post


Hope this helps,

Rui Barradas
Em 03-11-2012 16:07, dattel_palme escreveu:

Hi People!

I have following concern consisting of some steps to do in R:

I have an ascii file (table) consisting of many columns and rows.
1. I would like to order all values of the columns one under each other. It
will begin with column 1, then column 2 under column 1, column 3 under
column 2 etc. until at the end there is only 1 column. How do I do it?

2. Second problem is to make a scatterplot of two variables (I think after
further explanation scatter plot itself will not be needed). I have two
columns of two different variables (that I produces before), column 1 with
variable 1 and column 2 with variable 2. I would like to order them by one
variable and 0,01 interval (the varibale values will range between 0 and 1).
>From each 0,01 interval (100 intervals) i want to pick the maximum and
minimum value of variable 2.

3. From the obtained max and min of values of each interval i would like to
make a linear least square regression.

I hope someone can help me out!
Thanks
Stefan



--
View this message in context: 
http://r.789695.n4.nabble.com/some-help-tp4648316.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
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
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] some help

2012-11-03 Thread David Winsemius

On Nov 3, 2012, at 9:07 AM, dattel_palme wrote:

> Hi People!
> 
> I have following concern consisting of some steps to do in R: 
> 
> I have an ascii file (table) consisting of many columns and rows. 
> 1. I would like to order all values of the columns one under each other. It
> will begin with column 1, then column 2 under column 1, column 3 under
> column 2 etc. until at the end there is only 1 column. How do I do it?

something along the lines of 

dat <- read.table(filename, sep=, header=TRUE)
stacked <- do.call(rbind, dat)


> 
> 2. Second problem is to make a scatterplot of two variables (I think after
> further explanation scatter plot itself will not be needed). I have two
> columns of two different variables (that I produces before),

Did you now? But from the data produced above you only have one column. Is this 
another data-object where these column have names?

> column 1 with
> variable 1 and column 2 with variable 2. I would like to order them by one
> variable and 0,01 interval (the varibale values will range between 0 and 1).
>> From each 0,01 interval (100 intervals) i want to pick the maximum and
> minimum value of variable 2. 
> 

That is incoherent to this native speaker of English who is sometimes confused 
by presentations of problems without concrete references. An example would help 
greatly.


> 3. From the obtained max and min of values of each interval i would like to
> make a linear least square regression. 

Definitely need an example. Please read the Posting Guide.

-- 
> __
> R-help@r-project.org mailing list
> 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.

David Winsemius, MD
Alameda, CA, USA

__
R-help@r-project.org mailing list
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] some help

2012-11-03 Thread dattel_palme
Hi People!

I have following concern consisting of some steps to do in R: 

I have an ascii file (table) consisting of many columns and rows. 
1. I would like to order all values of the columns one under each other. It
will begin with column 1, then column 2 under column 1, column 3 under
column 2 etc. until at the end there is only 1 column. How do I do it?

2. Second problem is to make a scatterplot of two variables (I think after
further explanation scatter plot itself will not be needed). I have two
columns of two different variables (that I produces before), column 1 with
variable 1 and column 2 with variable 2. I would like to order them by one
variable and 0,01 interval (the varibale values will range between 0 and 1).
>From each 0,01 interval (100 intervals) i want to pick the maximum and
minimum value of variable 2. 

3. From the obtained max and min of values of each interval i would like to
make a linear least square regression. 

I hope someone can help me out!
Thanks
Stefan



--
View this message in context: 
http://r.789695.n4.nabble.com/some-help-tp4648316.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
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] some help to improve "hist to plot relative frequencies"

2012-06-18 Thread Deepayan Sarkar
On Fri, Jun 15, 2012 at 9:22 PM, gianni lavaredo
 wrote:
> Dear Researches,
>
> sorry for disturb. I wish to improve my figure in R plotting the relative
> frequencies of my data set.
>
> library(lattice)
> a <- c(0,0,0,1,1,2,4,5,6,7,7,7,7,7,8,8,8,8,9,9,9,9,10,10,11)
> histogram(a, xlab="myData")
>
> what i wish to do is:
>
> 1) invert the order of X and Y (eg: Precent of Total on X-axis and "MyData"
> on X-axis)
> 2) plot not the bar of histogram but a line (i tried with
> "lines(density(a))" but the result is not what i wish)

Take your pick:

ta <- table(a)

dotplot(ta, type = "h", lwd = 2, origin = 0)

dotplot(100 * prop.table(ta), type = "h", lwd = 2, origin = 0,
xlab = "Percent of total")

xyplot(as.numeric(names(ta)) ~ 100 * prop.table(ta),
   type = "h", lwd = 2, origin = 0, horizontal = TRUE,
   xlab = "Percent of total", ylab = "myData",
   xlim = c(-1, NA))

-Deepayan

__
R-help@r-project.org mailing list
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] some help to improve "hist to plot relative frequencies"

2012-06-15 Thread gianni lavaredo
Dear Researches,

sorry for disturb. I wish to improve my figure in R plotting the relative
frequencies of my data set.

library(lattice)
a <- c(0,0,0,1,1,2,4,5,6,7,7,7,7,7,8,8,8,8,9,9,9,9,10,10,11)
histogram(a, xlab="myData")

what i wish to do is:

1) invert the order of X and Y (eg: Precent of Total on X-axis and "MyData"
on X-axis)
2) plot not the bar of histogram but a line (i tried with
"lines(density(a))" but the result is not what i wish)

Great Thanks for any helps
Gianni

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] Some help needed

2012-05-08 Thread li li
Dear all,
 For the following code, I have the error message
"Error in uniroot(f1star, lower = -10, upper = 0, tol = 1e-10, lambda =
lam[i],  :
  f() values at end points not of opposite sign".

It seems the problem occurs when lambda is equal to 0.99.
However, there should be a solution for "f1star(lamda=0.99, p1=0.1, z)=0"
for z values.

 Thank you very much in advance for the help.

  Hannah





f1star <- function(lambda, p1,z){

lambda*((u1^2)*p1*exp(u1*z-u1^2/2)+(u2^2)*(0.2-p1)*exp(u2*z-u2^2/2))-(1-
lambda)*pi0}



f2star <- function(p1, cl, cu){

 pi0*(pnorm(cl)+(1-pnorm(cu)))/(pi0*(pnorm(cl)+(1-pnorm(cu)))+(u1^2)*p1*(
pnorm(cl-u1)+(1-pnorm(cu-u1)))+(u2^2)*(0.2-p1)*(pnorm(cl-u2)+(1-pnorm(cu-u2
}



f3star <- function(p1, cl, cu){

((u1^2)*p1*(pnorm(cu-u1)-pnorm(cl-u1))+(u2^2)*(0.2-p1)*(pnorm(cu-u2)-pnorm(
cl-u2)))/(pi0*(pnorm(cu)-pnorm(cl))+(u1^2)*p1*(pnorm(cu-u1)-pnorm(cl-u1))+(
u2^2)*(0.2-p1)*(pnorm(cu-u2)-pnorm(cl-u2)))}





p1 <- 0.1

lam <- seq(0.01,0.99, by=0.001)


x1 <- numeric(length(lam))

x2 <- numeric(length(lam))


for (i in 1:length(lam)){


cl <- uniroot(f1star, lower = -10, upper = 0,

tol = 1e-10,lambda=lam[i], p1=p1)$root


cu <- uniroot(f1star, lower = 0, upper = 10,

tol = 1e-10,lambda=lam[i], p1=p1)$root




x1[i]<- f2star(p1=p1, cl=cl, cu=cu)



x2[i]<- f3star(p1=p1,  cl=cl, cu=cu)}

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] Some Help Needed

2012-04-24 Thread peter dalgaard

On Apr 24, 2012, at 05:52 , li li wrote:

> Dear all,
>  I need to do some calculation where the code used are below. I get
> error message when I choose k to be large, say greater than 25.
> The error message is
> "Error in integrate(temp, lower = 0, upper = 1, k, x, rho, m) :
>  the integral is probably divergent".
> Can anyone give some help on resolving this. Thanks.

For the case at hand, adding stop.on.error=FALSE to the integrate() call 
probably works, but you need to be somewhat suspicious of the results and check 
carefully.

As a general matter, numerical integrators are confused by near-discontinuous 
behaviour. If you plot your integrand at one of the values where the 
integration fails:
 
curve(temp(y, 30, x=.06, rho, m), xname="y")

you'll see that it is 1 for y=0 then drops rapidly to zero, but not so quickly 
that it is completely flat for y>0. 

These things are tricky to work around, but it usually involves some sort of 
hinting to tell the integrator where "things are happening", which in turn may 
require mathematical analysis (pen-and-paper style) of the integrand, or crude 
guesswork. E.g., you could eyeball it and split into two integrals:

> integrate(temp, lower = 0, upper=.1, k=30, x=.06, rho,m)
0.000809987 with absolute error < 1.6e-05
> integrate(temp, lower = 0.1, upper=1, k=30, x=.06, rho,m)
1.444079e-09 with absolute error < 1.1e-11

(Notice that the result is well below your target of 0.05, which is why I said 
that you could probably get away with using stop.on.error -- all you really 
need is that the integral is too small for x=.06)

You could also utilze the fact that the integrand is a rather nicer function of 
log(y)

> curve(temp(y, 30, x=.06, rho, m), xname="y", log="x", from=1e-6 )
  
and consider integration by substitution:

> temp2 <- function(u,...) {y <- exp(u); y*temp(y,...)}
> integrate(temp2, lower = -Inf, upper=0, k=30, x=.06, rho, m)
0.0008099758 with absolute error < 3.7e-05



>   Hannah
> 
> m <- 100
> 
> alpha <- 0.05
> 
> rho <- 0.1
> 
> 
> 
> F0 <- function(y,x,rho){
> 
> pnorm((qnorm(x, lower.tail = F)-sqrt(rho)*qnorm(y, lower.tail = F))/sqrt(1-
> rho), lower.tail = F)
> 
> }
> 
>   temp <- function(y,k,x,rho,m) {
> 
> t <- F0(y=y, x=x, rho=rho)
> 
> pbinom(q=k, size=m, prob=t, lower.tail = F, log.p = FALSE)
> 
>}
> 
> 
> 
> est <- function(k,x,rho,m) {
> 
> integrate(temp, lower = 0, upper=1, k,x, rho,m)$value-alpha}
> 
> 
> 
> estf <- function(x){est(x, k=30, rho=rho, m=m)}
> 
> thre <- uniroot(estf, c(0,1), tol=1/10^12)$root
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> 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.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com

__
R-help@r-project.org mailing list
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] Some Help Needed

2012-04-23 Thread li li
Dear all,
  I need to do some calculation where the code used are below. I get
error message when I choose k to be large, say greater than 25.
The error message is
"Error in integrate(temp, lower = 0, upper = 1, k, x, rho, m) :
  the integral is probably divergent".
Can anyone give some help on resolving this. Thanks.
   Hannah

m <- 100

alpha <- 0.05

rho <- 0.1



F0 <- function(y,x,rho){

pnorm((qnorm(x, lower.tail = F)-sqrt(rho)*qnorm(y, lower.tail = F))/sqrt(1-
rho), lower.tail = F)

}

   temp <- function(y,k,x,rho,m) {

t <- F0(y=y, x=x, rho=rho)

pbinom(q=k, size=m, prob=t, lower.tail = F, log.p = FALSE)

}



est <- function(k,x,rho,m) {

integrate(temp, lower = 0, upper=1, k,x, rho,m)$value-alpha}



estf <- function(x){est(x, k=30, rho=rho, m=m)}

thre <- uniroot(estf, c(0,1), tol=1/10^12)$root

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] some help

2010-03-06 Thread Ibrahim henaish



 I am 
working  on bayesian copula but i am new in this area and i do not
have much knowledge about it. Does any one know  how to use  bayesian copula 
using R with
winbugs? and estimating missing data by R? 
 
hena...@yahoo.com
sincerely


  
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] some help regarding combining columns from different files

2010-01-12 Thread Simon Knapp
Hi Hari,

You have not given examples of 'list1.bp.files.names' or
'list2.bp.files.names' and hence it is difficult to determine what the code
is trying to achieve. I will assume you want to create all pairwise merges
of the attached files. If this is indeed what you are doing, the problem is
not a problem at all, it is just that the intersection of values of the
variables geneDescription between any two files is the empty set, as is
demonstrated by the following code snippet (for each merge, TRUE is printed
if there is some overlap and FALSE is printed if there is not - a FALSE
implies concatenation in the code you have provided)

list1.bp.files.names <- list2.bp.files.names <-
c('colNamesgenesplitList1_alcoholMetobolic_genes.txt',
'colNamesgenesplitList1_cellcycle_genes.txt',
'colNamesgenesplitList2_alcoholMetabolism_genes.txt',
'colNamesgenesplitList2_cellcycle_genes.txt')

x.col.names <- y.col.names <-
c("genesymbol","geneDescription","orgSymbol","orgName")

for (i in 1:length(list1.bp.files.names)){
temp1 <-
read.table(list1.bp.files.names[i],sep="\t",header=T,stringsAsFactors=F,quote='"')
for (j in (i+1):length(list2.bp.files.names)){
if(i==length(list2.bp.files.names)) break
temp2 <-
read.table(list2.bp.files.names[j],sep="\t",header=T,stringsAsFactors=F,quote='"')
cat(any(apply(temp1, 1, function(x, y) x['geneDescription'] %in% y,
temp2['geneDescription'])), '\n')
}
}

A tip - there are trailing and/or leading whitespace on the variables
'geneDescription' and 'orgSymbol'. (in the latter case " RG " is a different
value to "RG"). This is probably going to give different results to what you
were expecting.

Hope this helps,
Simon Knapp

On Wed, Jan 13, 2010 at 8:48 AM, Harikrishnadhar wrote:

> Hi Jim,
>
> I am want to merge two files into one file :
>
> Here is my code . But the problem with this is that I am getting the 2nd
> file appended to the first when i write temp3 in my code to the text file.
> I
> am not sure what mistake I am doing .
>
> also find the test files to run the code .
>
> Please help me with this !!!
>
> temp1 <- NULL
> temp2 <- NULL
> x.col.names <-c("genesymbol","geneDescription","orgSymbol","orgName")
> y.col.names <- c("genesymbol","geneDescription","orgSymbol","orgName")
> for (i in 1:length(list1.bp.files.names)){
>temp1 <-
>
> read.table(list1.bp.files.names[i],sep="\t",header=T,stringsAsFactors=F,quote="\"")
>  for (j in 1:length(list2.bp.files.names)){
> temp2 <-
>
> read.table(list2.bp.files.names[j],sep="\t",header=T,stringsAsFactors=F,quote="\"")
>temp3 <- merge(temp1,temp2,by.x = x.col.names,by.y=y.col.names,all=T)
>myfile<-gsub("( )", "", paste("1_",merge.bp.files.names[i],".txt"))
>write.table(temp3,file=myfile,sep="\t",quote=FALSE,row.names=F)
>  }
>  }
> Thanks
> --Hari--
>
> __
> R-help@r-project.org mailing list
> 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
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] some help regarding combining columns from different files

2010-01-12 Thread Harikrishnadhar
Hi Jim,

I am want to merge two files into one file :

Here is my code . But the problem with this is that I am getting the 2nd
file appended to the first when i write temp3 in my code to the text file. I
am not sure what mistake I am doing .

also find the test files to run the code .

Please help me with this !!!

temp1 <- NULL
temp2 <- NULL
x.col.names <-c("genesymbol","geneDescription","orgSymbol","orgName")
y.col.names <- c("genesymbol","geneDescription","orgSymbol","orgName")
for (i in 1:length(list1.bp.files.names)){
temp1 <-
read.table(list1.bp.files.names[i],sep="\t",header=T,stringsAsFactors=F,quote="\"")
  for (j in 1:length(list2.bp.files.names)){
 temp2 <-
read.table(list2.bp.files.names[j],sep="\t",header=T,stringsAsFactors=F,quote="\"")
temp3 <- merge(temp1,temp2,by.x = x.col.names,by.y=y.col.names,all=T)
myfile<-gsub("( )", "", paste("1_",merge.bp.files.names[i],".txt"))
write.table(temp3,file=myfile,sep="\t",quote=FALSE,row.names=F)
  }
 }
Thanks
--Hari--
genesymbol  geneDescription orgSymbol   orgName
E2f5 e2f transcription factor 5  RG  Rattus norvegicus
Msh2muts homolog 2 (e. coli)RG  Rattus norvegicus
Kpna2   karyopherin (importin) alpha 2  RG  Rattus norvegicus
Gtpbp4  gtp binding protein 4   RG  Rattus norvegicus
Dtymk_predicted deoxythymidylate kinase (predicted) RG  Rattus 
norvegicus
Ruvbl1  ruvb-like protein 1 RG  Rattus norvegicus
Cetn2   centrin 2   RG  Rattus norvegicus
Foxm1   forkhead box m1 RG  Rattus norvegicus
Abtb1   ankyrin repeat and btb (poz) domain containing 1RG  Rattus 
norvegicus
Myc myelocytomatosis viral oncogene homolog (avian) RG  Rattus 
norvegicus
Il1binterleukin 1 beta  RG  Rattus norvegicus
Cdc20   cell division cycle 20 homolog (s. cerevisiae)  RG  Rattus 
norvegicus
Cdc25a  cell division cycle 25 homolog a (s. cerevisiae)RG  Rattus 
norvegicus
Kifc1   kinesin family member c1RG  Rattus norvegicus
Fancd2  fanconi anemia d2 protein   RG  Rattus norvegicus
Rhobrhob gene   RG  Rattus norvegicus
Clp1cardiac lineage protein 1   RG  Rattus norvegicus
Psmd1   proteasome (prosome, macropain) 26s subunit, non-atpase, 1  RG  
Rattus norvegicus
Mad2l1_predictedmad2 (mitotic arrest deficient, homolog)-like 1 (yeast) 
(predicted) RG  Rattus norvegicus
Dhcr24  24-dehydrocholesterol reductase RG  Rattus norvegicus
Ahr aryl hydrocarbon receptor   RG  Rattus norvegicus
Rnd3ras homolog gene family, member e   RG  Rattus norvegicus
Acvr1b  activin a receptor, type 1b RG  Rattus norvegicus
Mcm2_predicted  minichromosome maintenance deficient 2 mitotin (s. cerevisiae) 
(predicted)  RG  Rattus norvegicus
Mapre3  microtubule-associated protein, rp/eb family, member 3  RG  Rattus 
norvegicus
Mapre1  microtubule-associated protein, rp/eb family, member 1  RG  Rattus 
norvegicus
Tardbp  tar dna binding protein RG  Rattus norvegicus
Cdca3   cell division cycle associated 3RG  Rattus norvegicus
Ccnb1   cyclin b1   RG  Rattus norvegicus
Npm1nucleophosmin 1 RG  Rattus norvegicus
Pcafp300/cbp-associated factor  RG  Rattus norvegicus
Cdc2a   cell division cycle 2 homolog a (s. pombe)  RG  Rattus 
norvegicus
Dnajc2  dnaj (hsp40) homolog, subfamily c, member 2 RG  Rattus 
norvegicus
Dab2ip  disabled homolog 2 (drosophila) interacting protein RG  Rattus 
norvegicus
Id2 inhibitor of dna binding 2, dominant negative helix-loop-helix protein  
RG  Rattus norvegicus
Kif23_predicted kinesin family member 23 (predicted)RG  Rattus 
norvegicus
Nek6nima (never in mitosis gene a)-related expressed kinase 6   RG  
Rattus norvegicus
Pola1   polymerase (dna directed), alpha 1  RG  Rattus norvegicus
Il1ainterleukin 1 alpha RG  Rattus norvegicus
Ccnccyclin cRG  Rattus norvegicus
Ccnb2   cyclin b2   RG  Rattus norvegicus
Pbef1   pre-b-cell colony enhancing factor 1RG  Rattus norvegicus
Rad17   rad17 homolog (s. pombe)RG  Rattus norvegicus
Racgap1_predicted   rac gtpase-activating protein 1 (predicted) RG  
Rattus norvegicus
Ccna2   cyclin a2   RG  Rattus norvegicus
Cdca8   cell division cycle associated 8RG  Rattus norvegicus
Sesn1_predicted sestrin 1 (predicted)   RG  Rattus norvegicus
Tpx2_predicted  tpx2, microtubule-associated protein homolog (xenopus laevis) 
(predicted)   RG  Rattus norvegicus
Dmtf1   cyclin d binding myb-like transcription factor 1RG  Rattus 
norvegicus
Chek1   checkpoint kinase 1 homolog (s. pombe)  RG  Rattus norvegicus
Mlh1mutl homolog 1 (e. coli)RG  Rattus norvegicus
Cgref1  cell growth regulator with ef hand

Re: [R] some help regarding combining columns from different files

2009-12-18 Thread jim holtman
In your function, you have

 temp <- read.table(fnames,header=T,sep="\t",stringsAsFactors=F,quote="\"")

I think you mean:

 temp <- read.table(i,header=T,sep="\t",stringsAsFactors=F,quote="\"")

Also 'files' is a parameter, but you are using 'fnames' in the 'for' loop;
shouldn't that be 'files'?

On Thu, Dec 17, 2009 at 3:51 PM, Harikrishnadhar wrote:

> Dear all,
>
> Here is my code which am using to combine 5th column from different data
> sets.
>
> Here is the function  to do my job
>
>
> genesymbol.append.file <-NULL
> gene.column <- NULL
> readGeneSymbol <- function(files,genesymbol.column=5){
> for(i in fnames){
>  temp <- read.table(fnames,header=T,sep="\t",stringsAsFactors=F,quote="\"")
>  gene.column<-cbind(gene.column,temp[,genesymbol.column])
>  genesymbol.append.file$genecolumns <- gene.column
>  genesymbol.append.file
>  }
> }
>
>
>
>
> test <- readGeneSymbol(fnames,genesymbol.column=5)
>
> Here is the warning message  am getting only the 5th column from the first
> column is taken
>
>
> Warning messages:
> 1: In file(file, "r") : only first element of 'description' argument used
> 2: In file(file, "r") : only first element of 'description' argument used
> >
>
> Please help me to solve this
>
>
>
>
>
>
>
> --
> Thanks
> Hari
> 215-385-4122
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> "If there is anyone out there who still doubts that America is a place
> where
> all things are possible"
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> 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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] some help regarding combining columns from different files

2009-12-17 Thread Harikrishnadhar
Dear all,

Here is my code which am using to combine 5th column from different data
sets.

Here is the function  to do my job


genesymbol.append.file <-NULL
gene.column <- NULL
readGeneSymbol <- function(files,genesymbol.column=5){
for(i in fnames){
 temp <- read.table(fnames,header=T,sep="\t",stringsAsFactors=F,quote="\"")
 gene.column<-cbind(gene.column,temp[,genesymbol.column])
 genesymbol.append.file$genecolumns <- gene.column
 genesymbol.append.file
 }
}




test <- readGeneSymbol(fnames,genesymbol.column=5)

Here is the warning message  am getting only the 5th column from the first
column is taken


Warning messages:
1: In file(file, "r") : only first element of 'description' argument used
2: In file(file, "r") : only first element of 'description' argument used
>

Please help me to solve this







-- 
Thanks
Hari
215-385-4122






















"If there is anyone out there who still doubts that America is a place where
all things are possible"

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] some help with plotting a beautiful structure using rgl

2009-08-13 Thread Nair, Murlidharan T
Ok, I was able to figure out one part by using rgl.spheres. I am still trying 
to insert text using rgl.texts. Does any one have a simple example? 


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Nair, Murlidharan T
Sent: Thursday, August 13, 2009 1:01 PM
To: r-help@r-project.org
Subject: [R] some help with plotting a beautiful structure using rgl

Hi!!

I need some help in using the correct required symbol when plotting my DNA 
structure  using rgl. I need to plot one strand using empty circles and the 
other using filled circles and if possible have sequence in the center.
I tried using pch and lty but have not been able to get it to do what I want. I 
am appending my code below. I have inserted comments when I need help.
Thanks../Murli
 
library(rgl)
library(scatterplot3d)
computed.DNA.Str<-structure(list(X = 1:42, x = c(-0.975688, 4.652834982, 
8.346905102, 
8.792265494, 5.763378778, 0.360110242, -5.410741675, -9.545558939, 
-10.41359287, -7.820469283, -2.87048497, 2.431822597, 5.780004735, 
5.864231475, -0.975688, -6.231531328, -9.096244856, -8.635565445, 
-4.93169249, 0.543553939, 5.641749313, 8.344319111, 7.415095348, 
3.257938171, -2.65307139, -8.1739403, -11.27397708, -11.05239614, 
0, 0, -0.074701006, -0.224103017, -0.373505029, -0.522907041, 
-0.672309052, -0.895991523, -1.193954453, -1.491917383, -1.789880313, 
-2.087843243, -2.459247906, -2.904094302), y = c(9.258795, 8.06401752, 
4.005465268, -1.499800943, -6.27267078, -8.411524903, -7.02084845, 
-2.355659798, 3.731366626, 9.104012958, 11.86675929, 11.12097881, 
7.538500525, 2.530292144, -9.258795, -6.917027485, -1.948188504, 
3.969960475, 8.447831953, 9.853576509, 7.728792788, 2.983125505, 
-2.290127499, -6.144106768, -6.950074829, -4.243530894, 1.04920276, 
7.296442545, 0, 0, 0.102817114, 0.308451342, 0.514085569, 0.719719797, 
0.925354025, 1.233226533, 1.643337323, 2.053448113, 2.463558902, 
2.873669692, 3.384864355, 3.997142893), z = c(-1.8, -5.19, -8.715110209, 
-12.46924956, -16.02528991, -19.31616462, -22.3760913, -25.15391125, 
-27.76053562, -30.76224274, -34.29278833, -38.28392979, -42.58508407, 
-47.00216668, 1.8, -1.59, -4.696196709, -7.756123397, -11.04699811, 
-14.60303845, -18.3571778, -22.4500669, -26.44120835, -29.97175395, 
-32.97346107, -35.58008544, -37.79845079, -40.14850635, 0, -3.39, 
-6.775228801, -10.1556864, -13.53614401, -16.91660161, -20.29705921, 
-23.66323008, -27.01511421, -30.36699834, -33.71888247, -37.07076661, 
-40.3989289, -43.70336934), seq = structure(c(2L, 2L, 1L, 1L, 
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 
1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 
2L, 2L, 2L, 2L, 1L, 1L), .Label = c("A", "T"), class = "factor")), .Names = 
c("X", 
"x", "y", "z", "seq"), class = "data.frame", row.names = c(NA, 
-42L))

dnaStr<-as.data.frame(computed.DNA.Str)
endPtlength<-length(dnaStr$x)
endPt1<-endPtlength/3
###
#The following code ensures that DNA is plotted in a cube
maxX<-max(dnaStr$x)
minX<-min(dnaStr$x)
minY<-min(dnaStr$y)
maxY<-max(dnaStr$y)
minZ<-min(dnaStr$z)
maxZ<-max(dnaStr$z)
difX<-abs(maxX-minX)
difY<-abs(maxY-minY)
difZ<-abs(maxZ-minZ)
angStrong<-round(max(difX,difY,difZ))
angStrongX<-(angStrong-difX)/2
angStrongY<-(angStrong-difY)/2
angStrongZ<-(angStrong-difZ)/2
minX<-minX-angStrongX
maxX<-maxX+angStrongX
minY<-minY-angStrongY
maxY<-maxY+angStrongY
minZ<-minZ-angStrongZ
maxZ<-maxZ+angStrongZ
###
#Plotting using rgl
###
#I would like to plot the following line using circles that are not filled

plot3dOut<-plot3d(dnaStr$x[1:endPt1],dnaStr$y[1:endPt1],dnaStr$z[1:endPt1], 
col="black", size=3, box=FALSE, axes=FALSE, lty="o", 
  xlim=c(minX,maxX), ylim=c(minY,maxY),zlim=c(minZ,maxZ), 
xlab="",ylab="",zlab="")


#I would like to plot the following lines using filled circles

points3d(dnaStr$x[(endPt1+1):(endPt1*2)],dnaStr$y[(endPt1+1):(endPt1*2)],dnaStr$z[(endPt1+1):(endPt1*2)],
 box=FALSE, col="black", axes=FALSE, size=3, pch=21)

#This is the center line, is it possible to put the sequence here using lty

lines3d(dnaStr$x[(endPt1*2+1):(endPtlength)],dnaStr$y[(endPt1*2+1):(endPtlength)],dnaStr$z[(endPt1*2+1):(endPtlength)],
 box=FALSE, col="black",axes=FALSE,size =1)
__
R-help@r-project.org mailing list
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] some help with plotting a beautiful structure using rgl

2009-08-13 Thread Nair, Murlidharan T
Hi!!

I need some help in using the correct required symbol when plotting my DNA 
structure  using rgl. I need to plot one strand using empty circles and the 
other using filled circles and if possible have sequence in the center.
I tried using pch and lty but have not been able to get it to do what I want. I 
am appending my code below. I have inserted comments when I need help.
Thanks../Murli
 
library(rgl)
library(scatterplot3d)
computed.DNA.Str<-structure(list(X = 1:42, x = c(-0.975688, 4.652834982, 
8.346905102, 
8.792265494, 5.763378778, 0.360110242, -5.410741675, -9.545558939, 
-10.41359287, -7.820469283, -2.87048497, 2.431822597, 5.780004735, 
5.864231475, -0.975688, -6.231531328, -9.096244856, -8.635565445, 
-4.93169249, 0.543553939, 5.641749313, 8.344319111, 7.415095348, 
3.257938171, -2.65307139, -8.1739403, -11.27397708, -11.05239614, 
0, 0, -0.074701006, -0.224103017, -0.373505029, -0.522907041, 
-0.672309052, -0.895991523, -1.193954453, -1.491917383, -1.789880313, 
-2.087843243, -2.459247906, -2.904094302), y = c(9.258795, 8.06401752, 
4.005465268, -1.499800943, -6.27267078, -8.411524903, -7.02084845, 
-2.355659798, 3.731366626, 9.104012958, 11.86675929, 11.12097881, 
7.538500525, 2.530292144, -9.258795, -6.917027485, -1.948188504, 
3.969960475, 8.447831953, 9.853576509, 7.728792788, 2.983125505, 
-2.290127499, -6.144106768, -6.950074829, -4.243530894, 1.04920276, 
7.296442545, 0, 0, 0.102817114, 0.308451342, 0.514085569, 0.719719797, 
0.925354025, 1.233226533, 1.643337323, 2.053448113, 2.463558902, 
2.873669692, 3.384864355, 3.997142893), z = c(-1.8, -5.19, -8.715110209, 
-12.46924956, -16.02528991, -19.31616462, -22.3760913, -25.15391125, 
-27.76053562, -30.76224274, -34.29278833, -38.28392979, -42.58508407, 
-47.00216668, 1.8, -1.59, -4.696196709, -7.756123397, -11.04699811, 
-14.60303845, -18.3571778, -22.4500669, -26.44120835, -29.97175395, 
-32.97346107, -35.58008544, -37.79845079, -40.14850635, 0, -3.39, 
-6.775228801, -10.1556864, -13.53614401, -16.91660161, -20.29705921, 
-23.66323008, -27.01511421, -30.36699834, -33.71888247, -37.07076661, 
-40.3989289, -43.70336934), seq = structure(c(2L, 2L, 1L, 1L, 
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 
1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 
2L, 2L, 2L, 2L, 1L, 1L), .Label = c("A", "T"), class = "factor")), .Names = 
c("X", 
"x", "y", "z", "seq"), class = "data.frame", row.names = c(NA, 
-42L))

dnaStr<-as.data.frame(computed.DNA.Str)
endPtlength<-length(dnaStr$x)
endPt1<-endPtlength/3
###
#The following code ensures that DNA is plotted in a cube
maxX<-max(dnaStr$x)
minX<-min(dnaStr$x)
minY<-min(dnaStr$y)
maxY<-max(dnaStr$y)
minZ<-min(dnaStr$z)
maxZ<-max(dnaStr$z)
difX<-abs(maxX-minX)
difY<-abs(maxY-minY)
difZ<-abs(maxZ-minZ)
angStrong<-round(max(difX,difY,difZ))
angStrongX<-(angStrong-difX)/2
angStrongY<-(angStrong-difY)/2
angStrongZ<-(angStrong-difZ)/2
minX<-minX-angStrongX
maxX<-maxX+angStrongX
minY<-minY-angStrongY
maxY<-maxY+angStrongY
minZ<-minZ-angStrongZ
maxZ<-maxZ+angStrongZ
###
#Plotting using rgl
###
#I would like to plot the following line using circles that are not filled

plot3dOut<-plot3d(dnaStr$x[1:endPt1],dnaStr$y[1:endPt1],dnaStr$z[1:endPt1], 
col="black", size=3, box=FALSE, axes=FALSE, lty="o", 
  xlim=c(minX,maxX), ylim=c(minY,maxY),zlim=c(minZ,maxZ), 
xlab="",ylab="",zlab="")


#I would like to plot the following lines using filled circles

points3d(dnaStr$x[(endPt1+1):(endPt1*2)],dnaStr$y[(endPt1+1):(endPt1*2)],dnaStr$z[(endPt1+1):(endPt1*2)],
 box=FALSE, col="black", axes=FALSE, size=3, pch=21)

#This is the center line, is it possible to put the sequence here using lty

lines3d(dnaStr$x[(endPt1*2+1):(endPtlength)],dnaStr$y[(endPt1*2+1):(endPtlength)],dnaStr$z[(endPt1*2+1):(endPtlength)],
 box=FALSE, col="black",axes=FALSE,size =1)
__
R-help@r-project.org mailing list
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] Some help with dates.

2008-06-20 Thread jim holtman
Check out 'POSIXlt'.  This should provide a hint as to how you can do it:

> ?as.POSIXlt
> x <- as.POSIXlt('2008-03-04 11:00')
> x
[1] "2008-03-04 11:00:00 GMT"
> unlist(x)
  sec   min  hour  mday   mon  year  wday  yday isdst
0 011 4 2   108 263 0
> ?POSIXlt
> myDate <- paste(x$wday, x$hour)
> myDate
[1] "2 11"
>


On Fri, Jun 20, 2008 at 4:35 AM, Paul Fisch <[EMAIL PROTECTED]> wrote:
> Hey,
>
> I'm new to R but familiar with other programming languages.
>
> Basically, I want to store an array of dates.  For each of these dates I
> want to store only the day of the week and the hour.  So for example:
> "Monday 12" would be Monday at 12 o'clock and "Tuesday 20" would be Tuesday
> at 8 p.m.
>
> Alternatively it could be stored as 0-6 for Sunday to Saturday.  So Tuesday
> at 11 a.m. would be something like "2 11".
>
> These dates don't need to be stored exactly like I have written.  I just
> would like to know how R would store a day of the week combined with an hour
> in a variable.
>
>
> Thanks,
> Paul
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> 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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

__
R-help@r-project.org mailing list
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] Some help with dates.

2008-06-20 Thread Paul Fisch
Hey,

I'm new to R but familiar with other programming languages.

Basically, I want to store an array of dates.  For each of these dates I
want to store only the day of the week and the hour.  So for example:
"Monday 12" would be Monday at 12 o'clock and "Tuesday 20" would be Tuesday
at 8 p.m.

Alternatively it could be stored as 0-6 for Sunday to Saturday.  So Tuesday
at 11 a.m. would be something like "2 11".

These dates don't need to be stored exactly like I have written.  I just
would like to know how R would store a day of the week combined with an hour
in a variable.


Thanks,
Paul

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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.