Re: [R] HISTOGRAM

2018-11-10 Thread Medic
Rui Barradas,
thank you for your prompt response, your code will be useful to me in
the future!

Rick Bilonick ("your data appear to be categorical"),
thank you very much for your comment (I would have to more correctly
express my task).

JIM Lemon,
THANKS!!! THIS IS EXACTLY what I needed!

__
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] HISTOGRAM

2018-11-10 Thread Jim Lemon
Hi Medic,
Perhaps this:

medic_df<-read.table(text="name number
ds6277
lk 24375
ax46049
dd70656
az216544
df 220620
gh641827",
header=TRUE)
library(plotrix)
options(scipen=10)
barp(medic_df$number,names.arg=medic_df$name,width=0.5)

As others have noted, this is really a barplot with no spaces between the bars.

Jim
On Sat, Nov 10, 2018 at 5:46 AM Medic  wrote:
>
> What would be the correct code (simplest version) (without gplot())
> for histogram (with 7 bars), which would include 7 names of bars under
> the X-axis. The data are:
>
> name number
> ds6277
> lk 24375
> ax46049
> dd70656
> az216544
> df 220620
> gh641827
>
> (I'm attaching mydata.r, making with dput.)
>
> My attempt is:
>
> options(scipen=999)
> with (mydata, hist(number))
>
> P.S. I can't understand how the column "name" to include in a 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-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] HISTOGRAM

2018-11-09 Thread Rick Bilonick
First, a histogram would not be appropriate (your data appear to be
categorical - a histogram is for continuous numeric vales) - you would need
a bar plot. You should make two vectors (one for the category names and the
other for the frequencies) and use the barplot function.

On Fri, Nov 9, 2018 at 1:46 PM Medic  wrote:

> What would be the correct code (simplest version) (without gplot())
> for histogram (with 7 bars), which would include 7 names of bars under
> the X-axis. The data are:
>
> name number
> ds6277
> lk 24375
> ax46049
> dd70656
> az216544
> df 220620
> gh641827
>
> (I'm attaching mydata.r, making with dput.)
>
> My attempt is:
>
> options(scipen=999)
> with (mydata, hist(number))
>
> P.S. I can't understand how the column "name" to include in a code
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>
> https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-helpdata=02%7C01%7Crab45%40pitt.edu%7C55f2571738b246f9dc1e08d646739b27%7C9ef9f489e0a04eeb87cc3a526112fd0d%7C1%7C0%7C636773859721875419sdata=haHuxll2%2FO0Dci0fSpd0evjfi0MTmLi0JoghvHxlz3o%3Dreserved=0
> PLEASE do read the posting guide
> https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.R-project.org%2Fposting-guide.htmldata=02%7C01%7Crab45%40pitt.edu%7C55f2571738b246f9dc1e08d646739b27%7C9ef9f489e0a04eeb87cc3a526112fd0d%7C1%7C0%7C636773859721875419sdata=aL6arSyKx4m9LBdOMhdhSpsdJmGCHubfdI%2Fns4Rgytw%3Dreserved=0
> 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.


Re: [R] HISTOGRAM

2018-11-09 Thread Rui Barradas

Hello,

You probably want a bar plot, not a histogram.

old.sci <- options(scipen=999)
with(mydata, barplot(number, space = 0, names.arg = name, beside = TRUE))
options(scipen = old.sci)


#-

mydata <- read.table(text = "
name number
ds6277
lk 24375
ax46049
dd70656
az216544
df 220620
gh641827
", header = TRUE)
mydata


Hope this helps,

Rui Barradas

Às 18:45 de 09/11/2018, Medic escreveu:

What would be the correct code (simplest version) (without gplot())
for histogram (with 7 bars), which would include 7 names of bars under
the X-axis. The data are:

name number
ds6277
lk 24375
ax46049
dd70656
az216544
df 220620
gh641827

(I'm attaching mydata.r, making with dput.)

My attempt is:

options(scipen=999)
with (mydata, hist(number))

P.S. I can't understand how the column "name" to include in a 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-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] HISTOGRAM

2018-11-09 Thread Medic
What would be the correct code (simplest version) (without gplot())
for histogram (with 7 bars), which would include 7 names of bars under
the X-axis. The data are:

name number
ds6277
lk 24375
ax46049
dd70656
az216544
df 220620
gh641827

(I'm attaching mydata.r, making with dput.)

My attempt is:

options(scipen=999)
with (mydata, hist(number))

P.S. I can't understand how the column "name" to include in a 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] histogram in GNU R....

2018-09-07 Thread Peter Langfelder
A simpler short term solution is to execute dev.off() and look for the plot
in file Rplots.pdf in the current directory. Depending on the OS of the
local computer, you should be able to point a file browser at the EC
instance and simply click the file to open in in a pdf viewer on the local
machine.

Peter

On Fri, Sep 7, 2018 at 10:31 AM William Dunlap via R-help <
r-help@r-project.org> wrote:

> You may have to install X11 stuff to your ec2 instance.  E.g., googling for
> "ec2 X11 forwarding" showed things like the following:
>
> Re: X11 forwarding to access AWS EC2 Linux instance
> Posted by: wilderfield
> 
> Posted on: Apr 5, 2018 11:31 AM
> [image: in response to: LE M.]
>  in
> response to: LE M.
> 
>   [image: Click to reply to this thread]
>  Reply
> 
> x11 
> sudo yum install xorg-x11-xauth
>
> The above is all I needed to get X11 forwarding working over ssh
>
> When ssh-ing to the instance, use the -X flag
>
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
> On Fri, Sep 7, 2018 at 1:26 AM, akshay kulkarni 
> wrote:
>
> > dear members,
> >  I am running R on Linux AWS ec2 instance.
> > When I try to create a histogram in it, I am running into problems:
> >
> > > xht <- c(1,2,3,4,5,6,7,8,9,10)
> > >  hist(xht)
> > >
> >
> > when I type hist(xht), it goes to the next prompt. More importantly,
> there
> > is no error message. So, the most probable conclusion is that the command
> > gets executed. But there is no pop up screen with a histogram, and
> nothing
> > else...
> >
> > whats going on?
> >
> > How can I circumvent the help of histogram(which is not available in GNU
> > R)? summary(xht) would help, but not much. Any other function that can
> give
> > information, in LINUX R, that a histogram gives, in LINUX CLI?
> >
> > Very many thanks for your time and effort...
> > Yours sincerely,
> > AKSHAYM KULKARNI
> >
> > [[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.
>

[[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: [R] histogram in GNU R....

2018-09-07 Thread William Dunlap via R-help
You may have to install X11 stuff to your ec2 instance.  E.g., googling for
"ec2 X11 forwarding" showed things like the following:

Re: X11 forwarding to access AWS EC2 Linux instance
Posted by: wilderfield

Posted on: Apr 5, 2018 11:31 AM
[image: in response to: LE M.]
 in
response to: LE M.

  [image: Click to reply to this thread]
 Reply

x11 
sudo yum install xorg-x11-xauth

The above is all I needed to get X11 forwarding working over ssh

When ssh-ing to the instance, use the -X flag


Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Fri, Sep 7, 2018 at 1:26 AM, akshay kulkarni 
wrote:

> dear members,
>  I am running R on Linux AWS ec2 instance.
> When I try to create a histogram in it, I am running into problems:
>
> > xht <- c(1,2,3,4,5,6,7,8,9,10)
> >  hist(xht)
> >
>
> when I type hist(xht), it goes to the next prompt. More importantly, there
> is no error message. So, the most probable conclusion is that the command
> gets executed. But there is no pop up screen with a histogram, and nothing
> else...
>
> whats going on?
>
> How can I circumvent the help of histogram(which is not available in GNU
> R)? summary(xht) would help, but not much. Any other function that can give
> information, in LINUX R, that a histogram gives, in LINUX CLI?
>
> Very many thanks for your time and effort...
> Yours sincerely,
> AKSHAYM KULKARNI
>
> [[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.


Re: [R] histogram in GNU R....

2018-09-07 Thread MacQueen, Don via R-help
In addition to the other suggestions, try typing

  x11()

before using hist().

That *should* start a graphics window. If it does not, then type

  capabilities()

and see if "X11" is TRUE.

-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/7/18, 1:26 AM, "R-help on behalf of akshay kulkarni" 
 wrote:

dear members,
 I am running R on Linux AWS ec2 instance.
When I try to create a histogram in it, I am running into problems:

> xht <- c(1,2,3,4,5,6,7,8,9,10)
>  hist(xht)
>

when I type hist(xht), it goes to the next prompt. More importantly, there 
is no error message. So, the most probable conclusion is that the command gets 
executed. But there is no pop up screen with a histogram, and nothing else...

whats going on?

How can I circumvent the help of histogram(which is not available in GNU 
R)? summary(xht) would help, but not much. Any other function that can give 
information, in LINUX R, that a histogram gives, in LINUX CLI?

Very many thanks for your time and effort...
Yours sincerely,
AKSHAYM KULKARNI

[[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] histogram in GNU R....

2018-09-07 Thread peter dalgaard
You are most likely plotting to a non-screen device. Check dev.list() after the 
hist(), and then the documentation for that device. It's probably pdf, and 
after quitting R, you should find that a file Rplots.pdf has been created.

-pd

> On 7 Sep 2018, at 10:26 , akshay kulkarni  wrote:
> 
> dear members,
> I am running R on Linux AWS ec2 instance.
> When I try to create a histogram in it, I am running into problems:
> 
>> xht <- c(1,2,3,4,5,6,7,8,9,10)
>> hist(xht)
>> 
> 
> when I type hist(xht), it goes to the next prompt. More importantly, there is 
> no error message. So, the most probable conclusion is that the command gets 
> executed. But there is no pop up screen with a histogram, and nothing else...
> 
> whats going on?
> 
> How can I circumvent the help of histogram(which is not available in GNU R)? 
> summary(xht) would help, but not much. Any other function that can give 
> information, in LINUX R, that a histogram gives, in LINUX CLI?
> 
> Very many thanks for your time and effort...
> Yours sincerely,
> AKSHAYM KULKARNI
> 
>   [[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.

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

__
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] histogram in GNU R....

2018-09-07 Thread Ivan Krylov
On Fri, 7 Sep 2018 08:26:22 +
akshay kulkarni  wrote:

> when I type hist(xht), it goes to the next prompt. More importantly,
> there is no error message. So, the most probable conclusion is that
> the command gets executed

Yes, hist() returns its value invisibly (try typing "? invisible" in
the R prompt without the quotes), which means that you don't see it, but
you can assign it to a variable and then view as usual:

> xht <- c(1,2,3,4,5,6,7,8,9,10)
> hxt <- hist(xht)
> hxt

You can also use the following trick:

> (hist(xht))

to see the invisible returned value without assigning it to a temporary
variable.

> But there is no pop up screen with a histogram, and nothing else...

As to why you cannot see a plot, it depends a lot on your setup. For
example, how exactly do you connect to the R instance running at AWS?
If you use plain SSH from your own Linux machine, try `ssh -X` to allow
the remote server to connect to the X graphics system on your machine
and display windows (alas, it gets very slow). What does `dev.cur()`
show after you run `hist(xht)`? On my machine, when I start R with no
available X connection, it automatically switches to the
non-interactive `pdf` graphics device; all plots get redirected to the
`Rplots.pdf` file in the current directory. Perhaps you can download
that file from the EC2 instance and view it locally?

-- 
Best regards,
Ivan

__
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] Histogram of character elements

2018-06-07 Thread Luigi Marongiu
Thank you Ben, this also works! I have a copy of the Sarkar but,
usually, I don't work with histograms. I'll brush it up, then. Best
regards, Luigi

On Thu, Jun 7, 2018 at 1:43 PM Ben Tupper  wrote:
>
> Hi again,
>
> I'm sort of pre-coffee still, but does this do it?  The data frame only has 
> one variable, a factor where the order of the levels is specified.
>
> library(lattice)
> group   <- c("a", "b", "c", "d", "e")
> freq<- c(1, 2, 2, 5, 3)
> x   <- rep(group, freq)
> df  <- data.frame(group = factor(x, levels = c("d", "a", "b", "c", "e")) )
> histogram(~ group, data = df)
>
> As far as super-grouping the answer is likely yes, but without details and an 
> example (and coffee) I'm at a loss.   I suggest getting a your hands on a 
> copy of https://www.r-project.org/doc/bib/R-books_bib.html#R:Sarkar:2008 It's 
> really worth it if you plan to spend time with lattice.
>
> Cheers,
> Ben
>
>
> On Jun 7, 2018, at 7:02 AM, Luigi Marongiu  wrote:
>
> also, with this approach, I need to re-arrange the data. Is it
> possible to work directly on a dataframe?
> On Thu, Jun 7, 2018 at 12:48 PM Ben Tupper  wrote:
>
>
> Hi,
>
> Is this what you are after?
>
> group <- c("a", "b", "c", "d", "e")
> freq <-c(1, 2, 2, 5, 3)
> x = rep(group, freq)
> barplot(table(x))
>
> Cheers,
> Ben
>
>
>
> On Jun 7, 2018, at 6:00 AM, Luigi Marongiu  wrote:
>
> Dear all,
> I have a dataframe with a column representing the names of the
> elements (a, b, etc) and one with their frequencies.
> How can I plot the frequencies so that each element has an associated
> frequency value?
> I have been thinking of a histogram, but I have found it difficult to
> implement. I have tried the following:
>
> group <- c("a", "b", "c", "d", "e")
> freq <-c(1, 2, 2, 5, 3)
> df <- data.frame(group, freq, stringsAsFactors = FALSE)
> hist(df$freq)
> library(lattice)
> histogram( ~ df$group)
> histogram( ~ as.factor(df$group))
> histogram(df$freq ~ as.factor(df$group))
>
> hist(df$freq) returns a histogram in which the values 1 and 2 appear 3
> times, the values 3 and 5 appear once and 4 never. This is not what I
> wanted; I want instead a graph telling me that a appears once, b twice
> etc.
>
> histogram( ~ df$group) gives the error:
> Error in hist.default(as.numeric(x), breaks = breaks, plot = FALSE,
> include.lowest = include.lowest,  :
> negative length vectors are not allowed
>
> histogram( ~ as.factor(df$group)) and histogram(df$freq ~
> as.factor(df$group)) report all groups on the x axis (that is good)
> but all at 20% level.
>
> What am I missing?
> Thank you.
>
> --
> Best regards,
> Luigi
>
> __
> 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.
>
>
> Ben Tupper
> Bigelow Laboratory for Ocean Sciences
> 60 Bigelow Drive, P.O. Box 380
> East Boothbay, Maine 04544
> http://www.bigelow.org
>
> Ecological Forecasting: https://eco.bigelow.org/
>
>
>
>
>
>
>
> --
> Best regards,
> Luigi
>
>
> Ben Tupper
> Bigelow Laboratory for Ocean Sciences
> 60 Bigelow Drive, P.O. Box 380
> East Boothbay, Maine 04544
> http://www.bigelow.org
>
> Ecological Forecasting: https://eco.bigelow.org/
>
>
>
>
>


-- 
Best regards,
Luigi

__
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] Histogram of character elements

2018-06-07 Thread Ben Tupper
Hi again,

I'm sort of pre-coffee still, but does this do it?  The data frame only has one 
variable, a factor where the order of the levels is specified.

library(lattice)
group   <- c("a", "b", "c", "d", "e")
freq<- c(1, 2, 2, 5, 3)
x   <- rep(group, freq)
df  <- data.frame(group = factor(x, levels = c("d", "a", "b", "c", "e")) )
histogram(~ group, data = df)

As far as super-grouping the answer is likely yes, but without details and an 
example (and coffee) I'm at a loss.   I suggest getting a your hands on a copy 
of https://www.r-project.org/doc/bib/R-books_bib.html#R:Sarkar:2008 
 It's really 
worth it if you plan to spend time with lattice.

Cheers,
Ben 


> On Jun 7, 2018, at 7:02 AM, Luigi Marongiu  wrote:
> 
> also, with this approach, I need to re-arrange the data. Is it
> possible to work directly on a dataframe?
> On Thu, Jun 7, 2018 at 12:48 PM Ben Tupper  wrote:
>> 
>> Hi,
>> 
>> Is this what you are after?
>> 
>> group <- c("a", "b", "c", "d", "e")
>> freq <-c(1, 2, 2, 5, 3)
>> x = rep(group, freq)
>> barplot(table(x))
>> 
>> Cheers,
>> Ben
>> 
>> 
>> 
>> On Jun 7, 2018, at 6:00 AM, Luigi Marongiu  wrote:
>> 
>> Dear all,
>> I have a dataframe with a column representing the names of the
>> elements (a, b, etc) and one with their frequencies.
>> How can I plot the frequencies so that each element has an associated
>> frequency value?
>> I have been thinking of a histogram, but I have found it difficult to
>> implement. I have tried the following:
>> 
>> group <- c("a", "b", "c", "d", "e")
>> freq <-c(1, 2, 2, 5, 3)
>> df <- data.frame(group, freq, stringsAsFactors = FALSE)
>> hist(df$freq)
>> library(lattice)
>> histogram( ~ df$group)
>> histogram( ~ as.factor(df$group))
>> histogram(df$freq ~ as.factor(df$group))
>> 
>> hist(df$freq) returns a histogram in which the values 1 and 2 appear 3
>> times, the values 3 and 5 appear once and 4 never. This is not what I
>> wanted; I want instead a graph telling me that a appears once, b twice
>> etc.
>> 
>> histogram( ~ df$group) gives the error:
>> Error in hist.default(as.numeric(x), breaks = breaks, plot = FALSE,
>> include.lowest = include.lowest,  :
>> negative length vectors are not allowed
>> 
>> histogram( ~ as.factor(df$group)) and histogram(df$freq ~
>> as.factor(df$group)) report all groups on the x axis (that is good)
>> but all at 20% level.
>> 
>> What am I missing?
>> Thank you.
>> 
>> --
>> Best regards,
>> Luigi
>> 
>> __
>> 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.
>> 
>> 
>> Ben Tupper
>> Bigelow Laboratory for Ocean Sciences
>> 60 Bigelow Drive, P.O. Box 380
>> East Boothbay, Maine 04544
>> http://www.bigelow.org
>> 
>> Ecological Forecasting: https://eco.bigelow.org/
>> 
>> 
>> 
>> 
>> 
> 
> 
> -- 
> Best regards,
> Luigi
> 

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Ecological Forecasting: https://eco.bigelow.org/






[[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: [R] Histogram of character elements

2018-06-07 Thread Luigi Marongiu
also, with this approach, I need to re-arrange the data. Is it
possible to work directly on a dataframe?
On Thu, Jun 7, 2018 at 12:48 PM Ben Tupper  wrote:
>
> Hi,
>
> Is this what you are after?
>
> group <- c("a", "b", "c", "d", "e")
> freq <-c(1, 2, 2, 5, 3)
> x = rep(group, freq)
> barplot(table(x))
>
> Cheers,
> Ben
>
>
>
> On Jun 7, 2018, at 6:00 AM, Luigi Marongiu  wrote:
>
> Dear all,
> I have a dataframe with a column representing the names of the
> elements (a, b, etc) and one with their frequencies.
> How can I plot the frequencies so that each element has an associated
> frequency value?
> I have been thinking of a histogram, but I have found it difficult to
> implement. I have tried the following:
>
> group <- c("a", "b", "c", "d", "e")
> freq <-c(1, 2, 2, 5, 3)
> df <- data.frame(group, freq, stringsAsFactors = FALSE)
> hist(df$freq)
> library(lattice)
> histogram( ~ df$group)
> histogram( ~ as.factor(df$group))
> histogram(df$freq ~ as.factor(df$group))
>
> hist(df$freq) returns a histogram in which the values 1 and 2 appear 3
> times, the values 3 and 5 appear once and 4 never. This is not what I
> wanted; I want instead a graph telling me that a appears once, b twice
> etc.
>
> histogram( ~ df$group) gives the error:
> Error in hist.default(as.numeric(x), breaks = breaks, plot = FALSE,
> include.lowest = include.lowest,  :
>  negative length vectors are not allowed
>
> histogram( ~ as.factor(df$group)) and histogram(df$freq ~
> as.factor(df$group)) report all groups on the x axis (that is good)
> but all at 20% level.
>
> What am I missing?
> Thank you.
>
> --
> Best regards,
> Luigi
>
> __
> 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.
>
>
> Ben Tupper
> Bigelow Laboratory for Ocean Sciences
> 60 Bigelow Drive, P.O. Box 380
> East Boothbay, Maine 04544
> http://www.bigelow.org
>
> Ecological Forecasting: https://eco.bigelow.org/
>
>
>
>
>


-- 
Best regards,
Luigi

__
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] Histogram of character elements

2018-06-07 Thread Luigi Marongiu
exactly! Thank you!
but it is possible to do it with lattice? I might have an extra level
of information, for instance super-group, and in that case, I could
plot all the supergroup easily together.
On Thu, Jun 7, 2018 at 12:48 PM Ben Tupper  wrote:
>
> Hi,
>
> Is this what you are after?
>
> group <- c("a", "b", "c", "d", "e")
> freq <-c(1, 2, 2, 5, 3)
> x = rep(group, freq)
> barplot(table(x))
>
> Cheers,
> Ben
>
>
>
> On Jun 7, 2018, at 6:00 AM, Luigi Marongiu  wrote:
>
> Dear all,
> I have a dataframe with a column representing the names of the
> elements (a, b, etc) and one with their frequencies.
> How can I plot the frequencies so that each element has an associated
> frequency value?
> I have been thinking of a histogram, but I have found it difficult to
> implement. I have tried the following:
>
> group <- c("a", "b", "c", "d", "e")
> freq <-c(1, 2, 2, 5, 3)
> df <- data.frame(group, freq, stringsAsFactors = FALSE)
> hist(df$freq)
> library(lattice)
> histogram( ~ df$group)
> histogram( ~ as.factor(df$group))
> histogram(df$freq ~ as.factor(df$group))
>
> hist(df$freq) returns a histogram in which the values 1 and 2 appear 3
> times, the values 3 and 5 appear once and 4 never. This is not what I
> wanted; I want instead a graph telling me that a appears once, b twice
> etc.
>
> histogram( ~ df$group) gives the error:
> Error in hist.default(as.numeric(x), breaks = breaks, plot = FALSE,
> include.lowest = include.lowest,  :
>  negative length vectors are not allowed
>
> histogram( ~ as.factor(df$group)) and histogram(df$freq ~
> as.factor(df$group)) report all groups on the x axis (that is good)
> but all at 20% level.
>
> What am I missing?
> Thank you.
>
> --
> Best regards,
> Luigi
>
> __
> 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.
>
>
> Ben Tupper
> Bigelow Laboratory for Ocean Sciences
> 60 Bigelow Drive, P.O. Box 380
> East Boothbay, Maine 04544
> http://www.bigelow.org
>
> Ecological Forecasting: https://eco.bigelow.org/
>
>
>
>
>


-- 
Best regards,
Luigi

__
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] Histogram of character elements

2018-06-07 Thread Ben Tupper
Hi,

Is this what you are after? 

group <- c("a", "b", "c", "d", "e")
freq <-c(1, 2, 2, 5, 3)
x = rep(group, freq)
barplot(table(x))

Cheers,
Ben



> On Jun 7, 2018, at 6:00 AM, Luigi Marongiu  wrote:
> 
> Dear all,
> I have a dataframe with a column representing the names of the
> elements (a, b, etc) and one with their frequencies.
> How can I plot the frequencies so that each element has an associated
> frequency value?
> I have been thinking of a histogram, but I have found it difficult to
> implement. I have tried the following:
> 
> group <- c("a", "b", "c", "d", "e")
> freq <-c(1, 2, 2, 5, 3)
> df <- data.frame(group, freq, stringsAsFactors = FALSE)
> hist(df$freq)
> library(lattice)
> histogram( ~ df$group)
> histogram( ~ as.factor(df$group))
> histogram(df$freq ~ as.factor(df$group))
> 
> hist(df$freq) returns a histogram in which the values 1 and 2 appear 3
> times, the values 3 and 5 appear once and 4 never. This is not what I
> wanted; I want instead a graph telling me that a appears once, b twice
> etc.
> 
> histogram( ~ df$group) gives the error:
> Error in hist.default(as.numeric(x), breaks = breaks, plot = FALSE,
> include.lowest = include.lowest,  :
>  negative length vectors are not allowed
> 
> histogram( ~ as.factor(df$group)) and histogram(df$freq ~
> as.factor(df$group)) report all groups on the x axis (that is good)
> but all at 20% level.
> 
> What am I missing?
> Thank you.
> 
> -- 
> Best regards,
> Luigi
> 
> __
> 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.
> 

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Ecological Forecasting: https://eco.bigelow.org/






[[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] Histogram of character elements

2018-06-07 Thread Luigi Marongiu
Dear all,
I have a dataframe with a column representing the names of the
elements (a, b, etc) and one with their frequencies.
How can I plot the frequencies so that each element has an associated
frequency value?
I have been thinking of a histogram, but I have found it difficult to
implement. I have tried the following:

group <- c("a", "b", "c", "d", "e")
freq <-c(1, 2, 2, 5, 3)
df <- data.frame(group, freq, stringsAsFactors = FALSE)
hist(df$freq)
library(lattice)
histogram( ~ df$group)
histogram( ~ as.factor(df$group))
histogram(df$freq ~ as.factor(df$group))

hist(df$freq) returns a histogram in which the values 1 and 2 appear 3
times, the values 3 and 5 appear once and 4 never. This is not what I
wanted; I want instead a graph telling me that a appears once, b twice
etc.

histogram( ~ df$group) gives the error:
Error in hist.default(as.numeric(x), breaks = breaks, plot = FALSE,
include.lowest = include.lowest,  :
  negative length vectors are not allowed

histogram( ~ as.factor(df$group)) and histogram(df$freq ~
as.factor(df$group)) report all groups on the x axis (that is good)
but all at 20% level.

What am I missing?
Thank you.

-- 
Best regards,
Luigi

__
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] Histogram plots in Lattice with spatialgrid dataframe data

2017-07-09 Thread Thomas Adams
Jeff,

Thank you! I know what I did was very inelegant and I understand about
providing a reproducible example; I just could not do it with my data -- I
guess I was too lazy to make up a toy one. I apologize about the email
formatting.

I would never have known to use 'stack', 'levels' 'gather' and 'mutate' --
still very much learning... so, I appreciate what you provided. Thank you
so much!

Tom


On Sun, Jul 9, 2017 at 10:16 PM, Jeff Newmiller 
wrote:

> Glad you found an answer, though it looks more self-educational than
> efficient (see suggestions below). In the future, follow the
> recommendations of the Posting Guide: use plain text, and provide a
> reproducible example. Some elaborations on what "reproducible" means are
> [1][2][3]. One issue here was that you did not include sample data to work
> with (I have assumed below that ann_bias has no other columns than the
> bias columns, which is not the usual case).
>
> There are a number of ways to achieve the reshaping of your ann_bias data
> frame that are less painful than your approach. For example, the base R
> "stack" function:
>
> bias2 <- stack( ann_bias )
> names( bias2 ) <- c( "bias", "year )
> levels( bias2$year ) <- sub( "bias", "", levels( bias2$year ) )
>
> Or... if you are willing to venture into the tidyverse...
>
> library(dplyr)
> library(tidyr)
> bias3  <- (   ann_bias
>  %>% gather( year, bias )
>  %>% mutate( year = factor( sub( "bias", "", year ) ) )
>  )
>
> [1] http://stackoverflow.com/questions/5963269/how-to-make-
> a-great-r-reproducible-example
>
> [2] http://adv-r.had.co.nz/Reproducibility.html
>
> [3] https://cran.r-project.org/web/packages/reprex/index.html
>
> --
> Sent from my phone. Please excuse my brevity.
>
> On July 9, 2017 12:32:32 PM PDT, Thomas Adams  wrote:
> >Hello all,
> >
> >After more digging I was able to find out how to do this. The answer
> >came
> >from an example here:
> >
> >https://stackoverflow.com/questions/3541713/how-to-plot-
> two-histograms-together-in-r
> >
> >
> >yr_1997<-data.frame(bias=ann_bias$bias1997)
> >yr_1998<-data.frame(bias=ann_bias$bias1998)
> >yr_1999<-data.frame(bias=ann_bias$bias1999)
> >yr_2000<-data.frame(bias=ann_bias$bias2000)
> >yr_2001<-data.frame(bias=ann_bias$bias2001)
> >yr_2002<-data.frame(bias=ann_bias$bias2002)
> >yr_2003<-data.frame(bias=ann_bias$bias2003)
> >yr_2004<-data.frame(bias=ann_bias$bias2004)
> >yr_2005<-data.frame(bias=ann_bias$bias2005)
> >yr_2006<-data.frame(bias=ann_bias$bias2006)
> >yr_2007<-data.frame(bias=ann_bias$bias2007)
> >yr_2008<-data.frame(bias=ann_bias$bias2008)
> >yr_2009<-data.frame(bias=ann_bias$bias2009)
> >yr_2010<-data.frame(bias=ann_bias$bias2010)
> >yr_2011<-data.frame(bias=ann_bias$bias2011)
> >yr_2012<-data.frame(bias=ann_bias$bias2012)
> >yr_2013<-data.frame(bias=ann_bias$bias2013)
> >yr_2014<-data.frame(bias=ann_bias$bias2014)
> >yr_2015<-data.frame(bias=ann_bias$bias2015)
> >yr_2016<-data.frame(bias=ann_bias$bias2016)
> >
> >
> >yr_1997$year<-'1997'
> >yr_1998$year<-'1998'
> >yr_1999$year<-'1999'
> >yr_2000$year<-'2000'
> >yr_2001$year<-'2001'
> >yr_2002$year<-'2002'
> >yr_2003$year<-'2003'
> >yr_2004$year<-'2004'
> >yr_2005$year<-'2005'
> >yr_2006$year<-'2006'
> >yr_2007$year<-'2007'
> >yr_2008$year<-'2008'
> >yr_2009$year<-'2009'
> >yr_2010$year<-'2010'
> >yr_2011$year<-'2011'
> >yr_2012$year<-'2012'
> >yr_2013$year<-'2013'
> >yr_2014$year<-'2014'
> >yr_2015$year<-'2015'
> >yr_2016$year<-'2016'
> >
> >
> >bias<-rbind(yr_1997,yr_1998,yr_1999,yr_2000,yr_2001,yr_
> 2002,yr_2003,yr_2004,yr_2005,yr_2006,yr_2007,yr_2008,yr_
> 2009,yr_2010,yr_2011,yr_2012,yr_2013,yr_2014,yr_2015,yr_2016)
> >histogram(~ bias | year, data=bias)
> >
> >Cheers!
> >Tom
> >
> >
> >On Sun, Jul 9, 2017 at 11:21 AM, Thomas Adams  wrote:
> >
> >> Hi all,
> >>
> >> I can not seem to get what I want using the Lattice package to
> >generate an
> >> array of histograms of
> >> spatialgrid dataframe data.
> >>
> >> I can use the sp package and spplot to generate an array of maps that
> >> display an array of spatialgrid dataframe data -- that's good. I
> >have:
> >>
> >> spplot(ann_bias,xlim=c(1423987.5,2614612.5),ylim=c(-
> >>
> >5862637.5,-4624387.5),at=brks,col.regions=colp(length(
> brks)-1),main="NOAA/NWS
> >> OHRFC Stage-3/MPE Precipitation Estimate Bias with respect to
> >PRISM\n1997 -
> >> 2016")
> >>
> >> Which works... I can also do histogram(ann_bias$bias1997), which
> >works
> >> too. I have also created a 'time-series' of boxplots successfully
> >with
> >> these data as well...
> >>
> >> But if I try:
> >>
> >> year<-c('1997','1998','1999','2000','2001','2002','2003','
> >> 2004','2005','2006','2007','2008','2009','2010','2011','
> >> 2012','2013','2014','2015','2016')
> >> dat<-c(ann_bias$bias1997,ann_bias$bias1998,ann_bias$
> >> bias1999,ann_bias$bias2000,ann_bias$bias2001,ann_bias$
> >> bias2002,ann_bias$bias2003,ann_bias$bias2004,ann_bias$
> >> 

Re: [R] Histogram plots in Lattice with spatialgrid dataframe data

2017-07-09 Thread Jeff Newmiller
Glad you found an answer, though it looks more self-educational than efficient 
(see suggestions below). In the future, follow the recommendations of the 
Posting Guide: use plain text, and provide a reproducible example. Some 
elaborations on what "reproducible" means are [1][2][3]. One issue here was 
that you did not include sample data to work with (I have assumed below that 
ann_bias has no other columns than the bias columns, which is not the usual 
case).

There are a number of ways to achieve the reshaping of your ann_bias data frame 
that are less painful than your approach. For example, the base R "stack" 
function:

bias2 <- stack( ann_bias )
names( bias2 ) <- c( "bias", "year )
levels( bias2$year ) <- sub( "bias", "", levels( bias2$year ) )

Or... if you are willing to venture into the tidyverse...

library(dplyr)
library(tidyr)
bias3  <- (   ann_bias
 %>% gather( year, bias )
 %>% mutate( year = factor( sub( "bias", "", year ) ) )
 )

[1] 
http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example

[2] http://adv-r.had.co.nz/Reproducibility.html

[3] https://cran.r-project.org/web/packages/reprex/index.html

-- 
Sent from my phone. Please excuse my brevity.

On July 9, 2017 12:32:32 PM PDT, Thomas Adams  wrote:
>Hello all,
>
>After more digging I was able to find out how to do this. The answer
>came
>from an example here:
>
>https://stackoverflow.com/questions/3541713/how-to-plot-two-histograms-together-in-r
>
>
>yr_1997<-data.frame(bias=ann_bias$bias1997)
>yr_1998<-data.frame(bias=ann_bias$bias1998)
>yr_1999<-data.frame(bias=ann_bias$bias1999)
>yr_2000<-data.frame(bias=ann_bias$bias2000)
>yr_2001<-data.frame(bias=ann_bias$bias2001)
>yr_2002<-data.frame(bias=ann_bias$bias2002)
>yr_2003<-data.frame(bias=ann_bias$bias2003)
>yr_2004<-data.frame(bias=ann_bias$bias2004)
>yr_2005<-data.frame(bias=ann_bias$bias2005)
>yr_2006<-data.frame(bias=ann_bias$bias2006)
>yr_2007<-data.frame(bias=ann_bias$bias2007)
>yr_2008<-data.frame(bias=ann_bias$bias2008)
>yr_2009<-data.frame(bias=ann_bias$bias2009)
>yr_2010<-data.frame(bias=ann_bias$bias2010)
>yr_2011<-data.frame(bias=ann_bias$bias2011)
>yr_2012<-data.frame(bias=ann_bias$bias2012)
>yr_2013<-data.frame(bias=ann_bias$bias2013)
>yr_2014<-data.frame(bias=ann_bias$bias2014)
>yr_2015<-data.frame(bias=ann_bias$bias2015)
>yr_2016<-data.frame(bias=ann_bias$bias2016)
>
>
>yr_1997$year<-'1997'
>yr_1998$year<-'1998'
>yr_1999$year<-'1999'
>yr_2000$year<-'2000'
>yr_2001$year<-'2001'
>yr_2002$year<-'2002'
>yr_2003$year<-'2003'
>yr_2004$year<-'2004'
>yr_2005$year<-'2005'
>yr_2006$year<-'2006'
>yr_2007$year<-'2007'
>yr_2008$year<-'2008'
>yr_2009$year<-'2009'
>yr_2010$year<-'2010'
>yr_2011$year<-'2011'
>yr_2012$year<-'2012'
>yr_2013$year<-'2013'
>yr_2014$year<-'2014'
>yr_2015$year<-'2015'
>yr_2016$year<-'2016'
>
>
>bias<-rbind(yr_1997,yr_1998,yr_1999,yr_2000,yr_2001,yr_2002,yr_2003,yr_2004,yr_2005,yr_2006,yr_2007,yr_2008,yr_2009,yr_2010,yr_2011,yr_2012,yr_2013,yr_2014,yr_2015,yr_2016)
>histogram(~ bias | year, data=bias)
>
>Cheers!
>Tom
>
>
>On Sun, Jul 9, 2017 at 11:21 AM, Thomas Adams  wrote:
>
>> Hi all,
>>
>> I can not seem to get what I want using the Lattice package to
>generate an
>> array of histograms of
>> spatialgrid dataframe data.
>>
>> I can use the sp package and spplot to generate an array of maps that
>> display an array of spatialgrid dataframe data -- that's good. I
>have:
>>
>> spplot(ann_bias,xlim=c(1423987.5,2614612.5),ylim=c(-
>>
>5862637.5,-4624387.5),at=brks,col.regions=colp(length(brks)-1),main="NOAA/NWS
>> OHRFC Stage-3/MPE Precipitation Estimate Bias with respect to
>PRISM\n1997 -
>> 2016")
>>
>> Which works... I can also do histogram(ann_bias$bias1997), which
>works
>> too. I have also created a 'time-series' of boxplots successfully
>with
>> these data as well...
>>
>> But if I try:
>>
>> year<-c('1997','1998','1999','2000','2001','2002','2003','
>> 2004','2005','2006','2007','2008','2009','2010','2011','
>> 2012','2013','2014','2015','2016')
>> dat<-c(ann_bias$bias1997,ann_bias$bias1998,ann_bias$
>> bias1999,ann_bias$bias2000,ann_bias$bias2001,ann_bias$
>> bias2002,ann_bias$bias2003,ann_bias$bias2004,ann_bias$
>> bias2005,ann_bias$bias2006,ann_bias$bias2007,ann_bias$
>> bias2008,ann_bias$bias2009,ann_bias$bias2010,ann_bias$
>> bias2011,ann_bias$bias2012,ann_bias$bias2013,ann_bias$
>> bias2014,ann_bias$bias2015,ann_bias$bias2016)
>>
>> > data<-data.frame(year=c(year),bias=c(dat))
>> > histogram(~ bias | year, data=data)
>>
>> I get a lattice plot of histograms, where the years vary, but all the
>> histograms are identical, which I know they should not be. It seem
>that all
>> the data from the combined spatialgrid dataframes are being used and
>> repeated.
>>
>> Obviously, I'm not constructing the data correctly. Can someone tell
>me
>> what I doing wrong. I've poured over this for a solid day, now...
>>
>> Regards,
>> Tom
>>
>>
>
>   [[alternative 

Re: [R] Histogram plots in Lattice with spatialgrid dataframe data

2017-07-09 Thread Thomas Adams
Hello all,

After more digging I was able to find out how to do this. The answer came
from an example here:

https://stackoverflow.com/questions/3541713/how-to-plot-two-histograms-together-in-r


yr_1997<-data.frame(bias=ann_bias$bias1997)
yr_1998<-data.frame(bias=ann_bias$bias1998)
yr_1999<-data.frame(bias=ann_bias$bias1999)
yr_2000<-data.frame(bias=ann_bias$bias2000)
yr_2001<-data.frame(bias=ann_bias$bias2001)
yr_2002<-data.frame(bias=ann_bias$bias2002)
yr_2003<-data.frame(bias=ann_bias$bias2003)
yr_2004<-data.frame(bias=ann_bias$bias2004)
yr_2005<-data.frame(bias=ann_bias$bias2005)
yr_2006<-data.frame(bias=ann_bias$bias2006)
yr_2007<-data.frame(bias=ann_bias$bias2007)
yr_2008<-data.frame(bias=ann_bias$bias2008)
yr_2009<-data.frame(bias=ann_bias$bias2009)
yr_2010<-data.frame(bias=ann_bias$bias2010)
yr_2011<-data.frame(bias=ann_bias$bias2011)
yr_2012<-data.frame(bias=ann_bias$bias2012)
yr_2013<-data.frame(bias=ann_bias$bias2013)
yr_2014<-data.frame(bias=ann_bias$bias2014)
yr_2015<-data.frame(bias=ann_bias$bias2015)
yr_2016<-data.frame(bias=ann_bias$bias2016)


yr_1997$year<-'1997'
yr_1998$year<-'1998'
yr_1999$year<-'1999'
yr_2000$year<-'2000'
yr_2001$year<-'2001'
yr_2002$year<-'2002'
yr_2003$year<-'2003'
yr_2004$year<-'2004'
yr_2005$year<-'2005'
yr_2006$year<-'2006'
yr_2007$year<-'2007'
yr_2008$year<-'2008'
yr_2009$year<-'2009'
yr_2010$year<-'2010'
yr_2011$year<-'2011'
yr_2012$year<-'2012'
yr_2013$year<-'2013'
yr_2014$year<-'2014'
yr_2015$year<-'2015'
yr_2016$year<-'2016'


bias<-rbind(yr_1997,yr_1998,yr_1999,yr_2000,yr_2001,yr_2002,yr_2003,yr_2004,yr_2005,yr_2006,yr_2007,yr_2008,yr_2009,yr_2010,yr_2011,yr_2012,yr_2013,yr_2014,yr_2015,yr_2016)
histogram(~ bias | year, data=bias)

Cheers!
Tom


On Sun, Jul 9, 2017 at 11:21 AM, Thomas Adams  wrote:

> Hi all,
>
> I can not seem to get what I want using the Lattice package to generate an
> array of histograms of
> spatialgrid dataframe data.
>
> I can use the sp package and spplot to generate an array of maps that
> display an array of spatialgrid dataframe data -- that's good. I have:
>
> spplot(ann_bias,xlim=c(1423987.5,2614612.5),ylim=c(-
> 5862637.5,-4624387.5),at=brks,col.regions=colp(length(brks)-1),main="NOAA/NWS
> OHRFC Stage-3/MPE Precipitation Estimate Bias with respect to PRISM\n1997 -
> 2016")
>
> Which works... I can also do histogram(ann_bias$bias1997), which works
> too. I have also created a 'time-series' of boxplots successfully with
> these data as well...
>
> But if I try:
>
> year<-c('1997','1998','1999','2000','2001','2002','2003','
> 2004','2005','2006','2007','2008','2009','2010','2011','
> 2012','2013','2014','2015','2016')
> dat<-c(ann_bias$bias1997,ann_bias$bias1998,ann_bias$
> bias1999,ann_bias$bias2000,ann_bias$bias2001,ann_bias$
> bias2002,ann_bias$bias2003,ann_bias$bias2004,ann_bias$
> bias2005,ann_bias$bias2006,ann_bias$bias2007,ann_bias$
> bias2008,ann_bias$bias2009,ann_bias$bias2010,ann_bias$
> bias2011,ann_bias$bias2012,ann_bias$bias2013,ann_bias$
> bias2014,ann_bias$bias2015,ann_bias$bias2016)
>
> > data<-data.frame(year=c(year),bias=c(dat))
> > histogram(~ bias | year, data=data)
>
> I get a lattice plot of histograms, where the years vary, but all the
> histograms are identical, which I know they should not be. It seem that all
> the data from the combined spatialgrid dataframes are being used and
> repeated.
>
> Obviously, I'm not constructing the data correctly. Can someone tell me
> what I doing wrong. I've poured over this for a solid day, now...
>
> Regards,
> Tom
>
>

[[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] Histogram plots in Lattice with spatialgrid dataframe data

2017-07-09 Thread Thomas Adams
Hi all,

I can not seem to get what I want using the Lattice package to generate an
array of histograms of
spatialgrid dataframe data.

I can use the sp package and spplot to generate an array of maps that
display an array of spatialgrid dataframe data -- that's good. I have:

spplot(ann_bias,xlim=c(1423987.5,2614612.5),ylim=c(-5862637.5,-4624387.5),at=brks,col.regions=colp(length(brks)-1),main="NOAA/NWS
OHRFC Stage-3/MPE Precipitation Estimate Bias with respect to PRISM\n1997 -
2016")

Which works... I can also do histogram(ann_bias$bias1997), which works too.
I have also created a 'time-series' of boxplots successfully with these
data as well...

But if I try:

year<-c('1997','1998','1999','2000','2001','2002','2003','2004','2005','2006','2007','2008','2009','2010','2011','2012','2013','2014','2015','2016')
dat<-c(ann_bias$bias1997,ann_bias$bias1998,ann_bias$bias1999,ann_bias$bias2000,ann_bias$bias2001,ann_bias$bias2002,ann_bias$bias2003,ann_bias$bias2004,ann_bias$bias2005,ann_bias$bias2006,ann_bias$bias2007,ann_bias$bias2008,ann_bias$bias2009,ann_bias$bias2010,ann_bias$bias2011,ann_bias$bias2012,ann_bias$bias2013,ann_bias$bias2014,ann_bias$bias2015,ann_bias$bias2016)

> data<-data.frame(year=c(year),bias=c(dat))
> histogram(~ bias | year, data=data)

I get a lattice plot of histograms, where the years vary, but all the
histograms are identical, which I know they should not be. It seem that all
the data from the combined spatialgrid dataframes are being used and
repeated.

Obviously, I'm not constructing the data correctly. Can someone tell me
what I doing wrong. I've poured over this for a solid day, now...

Regards,
Tom

[[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: [R] histogram first bar wrong position

2016-12-23 Thread peter dalgaard

> On 22 Dec 2016, at 18:08 , William Dunlap via R-help  
> wrote:
> 
> As a practical matter, 'continuous' data must be discretized, so if you
> have long vectors of it you will run into this problem.

Yep, and it is a bit unfortunate that hist() tries to use "pretty" breakpoints, 
so that you will have data points on the boundaries, causing all the 
left/right/endpoint business to come into play. The truehist() function in MASS 
does somewhat better. 

For the case at hand, things are much improved by setting the breaks explicitly:

hist(y,freq=TRUE, col='red', breaks=0.5:6.5)

but as pointed out by others, it is a much better idea to do

plot(factor(y, levels=1:6))

or similar. 

Incidentally, what is the most handy way to get a plot with percentages instead 
of counts? This works, but seems a bit ham-fisted:

barplot(prop.table(table(factor(y, levels=1:6

-pd

> 
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
> 
> On Thu, Dec 22, 2016 at 8:19 AM, Martin Maechler > wrote:
> 
>>> itpro  
>>>on Thu, 22 Dec 2016 16:17:28 +0300 writes:
>> 
>>> Hi, everyone.
>>> I stumbled upon weird histogram behaviour.
>> 
>>> Consider this "dice emulator":
>>> Step 1: Generate uniform random array x of size N.
>>> Step 2: Multiply each item by six and round to next bigger integer
>> to get numbers 1 to 6.
>>> Step 3: Plot histogram.
>> 
 x<-runif(N)
 y<-ceiling(x*6)
 hist(y,freq=TRUE, col='orange')
>> 
>> 
>>> Now what I get with N=10
>> 
 x<-runif(10)
 y<-ceiling(x*6)
 hist(y,freq=TRUE, col='green')
>> 
>>> At first glance looks OK.
>> 
>>> Now try N=100
>> 
 x<-runif(100)
 y<-ceiling(x*6)
 hist(y,freq=TRUE, col='red')
>> 
>>> Now first bar is not where it should be.
>>> Hmm. Look again to 10 histogram... First bar is not where I want
>> it, it's only less striking due to narrow bars.
>> 
>>> So, first bar is always in wrong position. How do I fix it to make
>> perfectly spaced bars?
>> 
>> Don't use histograms *at all* for such discrete integer data.
>> 
>> N <- rpois(100, 5)
>> plot(table(N), lwd = 4)
>> 
>> Histograms should be only be used for continuous data (or discrete data
>> with "many" possible values).
>> 
>> It's a pain to see them so often "misused" for data like the 'N' above.
>> 
>> Martin Maechler,
>> ETH Zurich
>> 
>> __
>> 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.

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

__
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] histogram first bar wrong position

2016-12-23 Thread Martin Maechler
> William Dunlap 
> on Thu, 22 Dec 2016 09:08:35 -0800 writes:

> As a practical matter, 'continuous' data must be discretized, so if you
> have long vectors of it you will run into this problem.

> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com

Yes, it is true that on the computer and in statistics we never have
continuous data in the strict sense.

My point was  and still is that a histogram is a wrong graphical
tool to be used for visualizing a distribution
on a small finite set, as e.g., the dice rolls 'itpro' has used.

And yes, if (s)he used something like

   dice <- ceiling(6 * runif(100))

and really prefers to use  hist() over (something like)

   plot(table(dice), lwd = 6)

then an appropriate graphic would rather be

  hist(dice, freq=TRUE, col="orange", breaks = (31:(6*32))/32)

(and the default breaks from sample size N = 100'000 is indeed
 relatively close to that because as we both know the number of
 default breaks grows (slowly) with N).

For me, histograms are a (poor but easy to understand and
explain) version of density estimates  (where the underlying
density is wrt to the lebesgue measure or simlar).

Now back to large / long vectors of data:
If you need to bin large vectors, you will hopefully be binning
to rather 100's or 1000's of bins (because 1000 is still much
smaller than "large") and then you actually have computed the
data for a histogram yourself already; so I personally would
again prefer not to use hist(), but to write my own "3 line"
function that returns an "histogram" object which I'd call  plot(.) on.

So, maybe providing such a short function maybe useful, notably
on the ?hist  help page ?

Martin Maechler,
ETH Zurich


> On Thu, Dec 22, 2016 at 8:19 AM, Martin Maechler 
> wrote:

>> > itpro  
>> > on Thu, 22 Dec 2016 16:17:28 +0300 writes:
>> 
>> > Hi, everyone.
>> > I stumbled upon weird histogram behaviour.
>> 
>> > Consider this "dice emulator":
>> > Step 1: Generate uniform random array x of size N.
>> > Step 2: Multiply each item by six and round to next bigger integer
>> to get numbers 1 to 6.
>> > Step 3: Plot histogram.
>> 
>> >> x<-runif(N)
>> >> y<-ceiling(x*6)
>> >> hist(y,freq=TRUE, col='orange')
>> 
>> 
>> > Now what I get with N=10
>> 
>> >> x<-runif(10)
>> >> y<-ceiling(x*6)
>> >> hist(y,freq=TRUE, col='green')
>> 
>> > At first glance looks OK.
>> 
>> > Now try N=100
>> 
>> >> x<-runif(100)
>> >> y<-ceiling(x*6)
>> >> hist(y,freq=TRUE, col='red')
>> 
>> > Now first bar is not where it should be.
>> > Hmm. Look again to 10 histogram... First bar is not where I want
>> it, it's only less striking due to narrow bars.
>> 
>> > So, first bar is always in wrong position. How do I fix it to make
>> perfectly spaced bars?
>> 
>> Don't use histograms *at all* for such discrete integer data.
>> 
>> N <- rpois(100, 5)
>> plot(table(N), lwd = 4)
>> 
>> Histograms should be only be used for continuous data (or discrete data
>> with "many" possible values).
>> 
>> It's a pain to see them so often "misused" for data like the 'N' above.
>> 
>> Martin Maechler,
>> ETH Zurich
>> 
>> __
>> 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.


Re: [R] histogram first bar wrong position

2016-12-22 Thread Ted Harding
Willam has listed the lid on the essence of the problem, which is
that in R the way that breaks (and therefore counts) in a histogram
are evaluated is an area of long grass with lurking snakes!

To get a glimpse of this, have a look at
  ?hist
and in the seaction "Arguments", look at "breaks", "freq", "right".
Also see under "Details".

and, as suggested under "See also", look at
  ?nclass.Sturges

As William suggests, if you know what claa intervals you want,
create them yourself! For your example (with N=100), look at:

   hist(y,freq=TRUE, col='red', breaks=0.5+(0:6))

or

   hist(y,freq=TRUE, col='red', breaks=0.25+(0:12)/2)

Hoping this helps!
Best wishes,
Ted.


On 22-Dec-2016 16:36:34 William Dunlap via R-help wrote:
> Looking at the return value of hist will show you what is happening:
> 
>> x <- rep(1:6,10*(6:1))
>> z <- hist(x, freq=TRUE)
>> z
> $breaks
>  [1] 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0
> 
> $counts
>  [1] 60 50  0 40  0 30  0 20  0 10
> ...
> 
> The the first bin is [1-1.5], including both endpoints, while the other
> bins include only the upper endpoint.  I recommend defining your
> own breakpoints, ones don't include possible data points, as in
> 
>> print(hist(x, breaks=seq(min(x)-0.5, max(x)+0.5, by=1), freq=TRUE))
> $breaks
> [1] 0.5 1.5 2.5 3.5 4.5 5.5 6.5
> 
> $counts
> [1] 60 50 40 30 20 10
> ...
> 
> S+ had a 'factor' method for hist() that did this sort of thing, but R does
> not.
> 
> 
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
> 
> On Thu, Dec 22, 2016 at 5:17 AM, itpro  wrote:
> 
>> Hi, everyone.
>>
>>
>> I stumbled upon weird histogram behaviour.
>>
>> Consider this "dice emulator":
>> Step 1: Generate uniform random array x of size N.
>> Step 2: Multiply each item by six and round to next bigger integer to get
>> numbers 1 to 6.
>> Step 3: Plot histogram.
>>
>> > x<-runif(N)
>> > y<-ceiling(x*6)
>> > hist(y,freq=TRUE, col='orange')
>>
>>
>> Now what I get with N=10
>>
>> > x<-runif(10)
>> > y<-ceiling(x*6)
>> > hist(y,freq=TRUE, col='green')
>>
>> At first glance looks OK.
>>
>> Now try N=100
>>
>> > x<-runif(100)
>> > y<-ceiling(x*6)
>> > hist(y,freq=TRUE, col='red')
>>
>> Now first bar is not where it should be.
>> Hmm. Look again to 10 histogram... First bar is not where I want it,
>> it's only less striking due to narrow bars.
>>
>> So, first bar is always in wrong position. How do I fix it to make
>> perfectly spaced bars?
>>
>>
>>
>>
>>
>>
>> __
>> 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.

-
E-Mail: (Ted Harding) 
Date: 22-Dec-2016  Time: 17:23:26
This message was sent by XFMail

__
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] histogram first bar wrong position

2016-12-22 Thread William Dunlap via R-help
As a practical matter, 'continuous' data must be discretized, so if you
have long vectors of it you will run into this problem.

Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Thu, Dec 22, 2016 at 8:19 AM, Martin Maechler  wrote:

> > itpro  
> > on Thu, 22 Dec 2016 16:17:28 +0300 writes:
>
> > Hi, everyone.
> > I stumbled upon weird histogram behaviour.
>
> > Consider this "dice emulator":
> > Step 1: Generate uniform random array x of size N.
> > Step 2: Multiply each item by six and round to next bigger integer
> to get numbers 1 to 6.
> > Step 3: Plot histogram.
>
> >> x<-runif(N)
> >> y<-ceiling(x*6)
> >> hist(y,freq=TRUE, col='orange')
>
>
> > Now what I get with N=10
>
> >> x<-runif(10)
> >> y<-ceiling(x*6)
> >> hist(y,freq=TRUE, col='green')
>
> > At first glance looks OK.
>
> > Now try N=100
>
> >> x<-runif(100)
> >> y<-ceiling(x*6)
> >> hist(y,freq=TRUE, col='red')
>
> > Now first bar is not where it should be.
> > Hmm. Look again to 10 histogram... First bar is not where I want
> it, it's only less striking due to narrow bars.
>
> > So, first bar is always in wrong position. How do I fix it to make
> perfectly spaced bars?
>
> Don't use histograms *at all* for such discrete integer data.
>
>  N <- rpois(100, 5)
>  plot(table(N), lwd = 4)
>
> Histograms should be only be used for continuous data (or discrete data
> with "many" possible values).
>
> It's a pain to see them so often "misused" for data like the 'N' above.
>
> Martin Maechler,
> ETH Zurich
>
> __
> 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.


Re: [R] histogram first bar wrong position

2016-12-22 Thread William Dunlap via R-help
Looking at the return value of hist will show you what is happening:

> x <- rep(1:6,10*(6:1))
> z <- hist(x, freq=TRUE)
> z
$breaks
 [1] 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0

$counts
 [1] 60 50  0 40  0 30  0 20  0 10
...

The the first bin is [1-1.5], including both endpoints, while the other
bins include only the upper endpoint.  I recommend defining your
own breakpoints, ones don't include possible data points, as in

> print(hist(x, breaks=seq(min(x)-0.5, max(x)+0.5, by=1), freq=TRUE))
$breaks
[1] 0.5 1.5 2.5 3.5 4.5 5.5 6.5

$counts
[1] 60 50 40 30 20 10
...

S+ had a 'factor' method for hist() that did this sort of thing, but R does
not.


Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Thu, Dec 22, 2016 at 5:17 AM, itpro  wrote:

> Hi, everyone.
>
>
> I stumbled upon weird histogram behaviour.
>
> Consider this "dice emulator":
> Step 1: Generate uniform random array x of size N.
> Step 2: Multiply each item by six and round to next bigger integer to get
> numbers 1 to 6.
> Step 3: Plot histogram.
>
> > x<-runif(N)
> > y<-ceiling(x*6)
> > hist(y,freq=TRUE, col='orange')
>
>
> Now what I get with N=10
>
> > x<-runif(10)
> > y<-ceiling(x*6)
> > hist(y,freq=TRUE, col='green')
>
> At first glance looks OK.
>
> Now try N=100
>
> > x<-runif(100)
> > y<-ceiling(x*6)
> > hist(y,freq=TRUE, col='red')
>
> Now first bar is not where it should be.
> Hmm. Look again to 10 histogram... First bar is not where I want it,
> it's only less striking due to narrow bars.
>
> So, first bar is always in wrong position. How do I fix it to make
> perfectly spaced bars?
>
>
>
>
>
>
> __
> 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.


Re: [R] histogram first bar wrong position

2016-12-22 Thread Martin Maechler
> itpro  
> on Thu, 22 Dec 2016 16:17:28 +0300 writes:

> Hi, everyone.
> I stumbled upon weird histogram behaviour.

> Consider this "dice emulator":
> Step 1: Generate uniform random array x of size N.
> Step 2: Multiply each item by six and round to next bigger integer to get 
numbers 1 to 6.
> Step 3: Plot histogram.

>> x<-runif(N)
>> y<-ceiling(x*6)
>> hist(y,freq=TRUE, col='orange')


> Now what I get with N=10

>> x<-runif(10)
>> y<-ceiling(x*6)
>> hist(y,freq=TRUE, col='green')

> At first glance looks OK.

> Now try N=100

>> x<-runif(100)
>> y<-ceiling(x*6)
>> hist(y,freq=TRUE, col='red')

> Now first bar is not where it should be.
> Hmm. Look again to 10 histogram... First bar is not where I want it, 
it's only less striking due to narrow bars.

> So, first bar is always in wrong position. How do I fix it to make 
perfectly spaced bars?

Don't use histograms *at all* for such discrete integer data.

 N <- rpois(100, 5)
 plot(table(N), lwd = 4)

Histograms should be only be used for continuous data (or discrete data
with "many" possible values).

It's a pain to see them so often "misused" for data like the 'N' above.

Martin Maechler,
ETH Zurich

__
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] histogram first bar wrong position

2016-12-22 Thread itpro
Hi, everyone.


I stumbled upon weird histogram behaviour.

Consider this "dice emulator":
Step 1: Generate uniform random array x of size N.
Step 2: Multiply each item by six and round to next bigger integer to get 
numbers 1 to 6.
Step 3: Plot histogram.

> x<-runif(N)
> y<-ceiling(x*6)
> hist(y,freq=TRUE, col='orange')


Now what I get with N=10

> x<-runif(10)
> y<-ceiling(x*6)
> hist(y,freq=TRUE, col='green')

At first glance looks OK.

Now try N=100

> x<-runif(100)
> y<-ceiling(x*6)
> hist(y,freq=TRUE, col='red')

Now first bar is not where it should be.
Hmm. Look again to 10 histogram... First bar is not where I want it, it's 
only less striking due to narrow bars.

So, first bar is always in wrong position. How do I fix it to make perfectly 
spaced bars?





__
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] Histogram using Sturges' Bining Errors

2016-10-02 Thread Jim Lemon
Hi Elysa,
This is pretty much a guess. If you understand the first error, i.e.
that there are nine rows in your input data frame (?) that contain NA,
NaN, or Inf values, have you tried manually removing those rows and
feeding the remainder to your code?

Jim


On Sun, Oct 2, 2016 at 7:19 PM, Elysa Mitova  wrote:
> Histogram using Sturges' bining
>
> Hello,
>
> I am trying to create a histogram using Sturges' bining rule, yet I keep
> getting 2 errors, which probably have to do with the variable I am using.
>
> Here is my process and the errors, what would you suggest?
>
> k <- ggplot (world, aes (x=polstab))
>
> wid <- ceiling ((max(world$polstab)- min (world$polstab))/
> nclass.Sturges(world$polstab))
>
> k + geom_histogram(col = "black", fill = "white", binwidth = wid)
>
> Now, I get two error messages:
>
> 1: Removed 9 rows containing non-finite values (stat_bin).
> 2: Computation failed in `stat_bin()`:
> missing value where TRUE/FALSE needed
>
> The first one I understand, the second one is more problematic. What could
> I do to remove this error?
>
>
>
> Thank you in advance!
>
> [[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] Histogram using Sturges' Bining Errors

2016-10-02 Thread Elysa Mitova
Histogram using Sturges' bining

Hello,

I am trying to create a histogram using Sturges' bining rule, yet I keep
getting 2 errors, which probably have to do with the variable I am using.

Here is my process and the errors, what would you suggest?

k <- ggplot (world, aes (x=polstab))

wid <- ceiling ((max(world$polstab)- min (world$polstab))/
nclass.Sturges(world$polstab))

k + geom_histogram(col = "black", fill = "white", binwidth = wid)

Now, I get two error messages:

1: Removed 9 rows containing non-finite values (stat_bin).
2: Computation failed in `stat_bin()`:
missing value where TRUE/FALSE needed

The first one I understand, the second one is more problematic. What could
I do to remove this error?



Thank you in advance!

[[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: [R] Histogram with a wide range of numbers.

2016-01-21 Thread Jim Lemon
Hi Sema,
I trimmed your file to the first 220 lines.

ads<-read.table("all_data_scor.txt",header=TRUE,sep="\t")
ads.tab<-table(cut(all_data_scor[,2],breaks=c(0,1e-100,1e-10,1e-1,1,10)))
barplot(adt.tab)

This gives you a basic idea of what can be done. If this is not clear, ask
again.

Jim


On Thu, Jan 21, 2016 at 8:16 PM, Sema Atasever  wrote:

> Dear Authorized Sir / Madam,
>
> I need your opinion on something R.
> I have a sample text file that includes eValue scores (2nd column).
> This column includes a wide range of numbers. For example: 1e-179 or 9.9
> You can find this text file in the attachment.
>
> How do I create a histogram in R with logarithmic scale or
> which method do i use these values which includes with a wide range of
> numbers.
>
> I would appreciate if you could advise on some methods.
>
> Thanks.
>
> __
> 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] Histogram for Left Censored Data

2015-12-31 Thread Steven Stoline
Dear All:

I need helps with creating histograms for data that include left censored
observations.

Here is an example of left censored data



*Sulfate.Concentration*
<-matrix(c(1450,1800,1840,1820,1860,1780,1760,1800,1900,1770,1790,1780,1850,1760,1450,1710,1575,1475,1780,1790,1780,1450,1790,1800,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0),24,2)


*Column 2* is an indicator for censoring "*1*" for left censored
observations and "*0*" for non-censored (fully measured) observations.

with many thanks
steve

-- 
Steven M. Stoline
1123 Forest Avenue
Portland, ME 04112
sstol...@gmail.com

[[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: [R] Histogram for Left Censored Data

2015-12-31 Thread Jim Lemon
Hi Steve,
Maybe something like this:

Sconc<-matrix(c(1450,1800,1840,1820,1860,1780,1760,1800,1900,
 1770,1790,1780,1850,1760,1450,1710,1575,1475,1780,1790,
 1780,1450,1790,1800,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0),
 24,2)
hist(Sconc[,1],breaks=c(1450,1550,1650,1750,1900))
abline(v=1450,col="red")
text(1550,0.003,"limit of measurement")
arrows(1480,0.003,1450,0.003)

Jim


On Thu, Dec 31, 2015 at 9:20 PM, Steven Stoline  wrote:

> Dear All:
>
> I need helps with creating histograms for data that include left censored
> observations.
>
> Here is an example of left censored data
>
>
>
> *Sulfate.Concentration*
>
> <-matrix(c(1450,1800,1840,1820,1860,1780,1760,1800,1900,1770,1790,1780,1850,1760,1450,1710,1575,1475,1780,1790,1780,1450,1790,1800,
> 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0),24,2)
>
>
> *Column 2* is an indicator for censoring "*1*" for left censored
> observations and "*0*" for non-censored (fully measured) observations.
>
> with many thanks
> steve
>
> --
> Steven M. Stoline
> 1123 Forest Avenue
> Portland, ME 04112
> sstol...@gmail.com
>
> [[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] Histogram from a single column of a data frame

2014-09-26 Thread Richard Lerner
Column 7 of oded is Breed. If I enter
 summary(Breed)
I get the counts of the numbers in each breed.
However, if I enter


I have tried

 hist($Breed)
Error: unexpected '$' in hist($

 hist(Breed)
Error in hist(Breed) : object 'Breed' not found

 hist(Breed)
Error in hist.default(Breed) : 'x' must be numeric

FYI

 colnames(oded)
[1] Subject.Name   Date   Species
AgeSex
[6] SpayedNeutered Breed  Breed.Code

How do I get a histogram of the counts in column 7?


Thanks
Richard

[[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] Histogram from a single column of a data frame

2014-09-26 Thread William Dunlap
Try
  hist(oded$Breed)

(I suspect that summary(Breed) does not work in your current session either -
perhaps you had a dataset named just Breed or had attached the data.frame
oded in the session where summary(Breed) works.)

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Fri, Sep 26, 2014 at 10:57 AM, Richard Lerner richa...@uchicago.edu wrote:
 Column 7 of oded is Breed. If I enter
 summary(Breed)
 I get the counts of the numbers in each breed.
 However, if I enter


 I have tried

 hist($Breed)
 Error: unexpected '$' in hist($

 hist(Breed)
 Error in hist(Breed) : object 'Breed' not found

 hist(Breed)
 Error in hist.default(Breed) : 'x' must be numeric

 FYI

 colnames(oded)
 [1] Subject.Name   Date   Species
 AgeSex
 [6] SpayedNeutered Breed  Breed.Code

 How do I get a histogram of the counts in column 7?


 Thanks
 Richard

 [[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-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] Histogram from a single column of a data frame

2014-09-26 Thread Rolf Turner

On 27/09/14 05:57, Richard Lerner wrote:

Column 7 of oded is Breed. If I enter

summary(Breed)

I get the counts of the numbers in each breed.
However, if I enter


I have tried


hist($Breed)

Error: unexpected '$' in hist($


hist(Breed)

Error in hist(Breed) : object 'Breed' not found


hist(Breed)

Error in hist.default(Breed) : 'x' must be numeric

FYI


colnames(oded)

[1] Subject.Name   Date   Species
AgeSex
[6] SpayedNeutered Breed  Breed.Code

How do I get a histogram of the counts in column 7?



Are you for real, or is this some kind of joke?

Assuming it's not a joke:

(1) Look at ?$.

(2) WTF do you expect hist($Breed) to do?  Where is Breed going to be 
found, for pity's sake?  You appear to have no understanding of how R 
(or any programming language) works.


Read the Introduction to R manual and *get* some understanding if you 
are going to use R.


(3) The correct usage obviously (and I mean ***really***; it *IS* 
obvious) is hist(oded$Breed) --- which tells hist() where to find Breed.


(4) You could also use

with(oded,hist(Breed))

which is a useful syntax in some circumstances.

cheers,

Rolf Turner

--
Rolf Turner
Technical Editor ANZJS

__
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] Histogram

2013-09-05 Thread David Carlson
I wasn't suggesting that much detail, but I think the addition
of one sentence in the last paragraph of the Details section
would make it the meaning of the number is a suggestion only
clearer. 

These functions provide a suggested number of bins that may be
modified to produce 'round' breakpoints covering the range of
the values in x.

Added just before the last sentence, Alternatively, . . .

Also pretty() could be added to the See Also section.


David Carlson

-Original Message-
From: Duncan Murdoch [mailto:murdoch.dun...@gmail.com] 
Sent: Wednesday, September 4, 2013 7:00 PM
To: dcarl...@tamu.edu
Cc: 'philippe massicotte'; 'Rui Barradas';
'r-help@R-project.org'
Subject: Re: [R] Histogram

On 13-09-04 4:44 PM, David Carlson wrote: Good question. It
turns out 
that the manual page does not tell
  the whole story.

Do you really think the manual page would be improved if it went
into as 
much detail as you give below?  It does say clearly that breaks
is a 
suggestion only.  I don't think it would be clearer if it
explained 
exactly how the suggestion is used. It would just be more
complicated, 
and less likely to be read.

Duncan Murdoch


  Looking at the source code for hist.default,
  the function starts with the number of breaks suggested by
  nclass.Sturges(), but then this number (or any other number
of
  breaks that you specify) is passed to pretty() along with the
  maximum and the minimum values of the data (ie range(data))
to
  create pretty break intervals. In your example,
  nclass.Sturges() always recommends 8 breaks, but the number
of
  the breaks changes based on the minimum and maximum values.
So
  the only way to get exactly the number of breaks you want is
to
  specify the break intervals yourself.
 
  David Carlson
 
 
  -Original Message-
  From: r-help-boun...@r-project.org
  [mailto:r-help-boun...@r-project.org] On Behalf Of philippe
  massicotte
  Sent: Wednesday, September 4, 2013 3:02 PM
  To: Rui Barradas
  Cc: r-help@R-project.org
  Subject: Re: [R] Histogram
 
  Thank you everyone.
  Try executing this:
  replicate(100, length(hist(rnorm(100), nclass = 10)$counts))
  I'm still not sure why the number of bins (classes) is not
  consistent.
  Thank in advance.
 
  Date: Wed, 4 Sep 2013 20:27:36 +0100
  From: ruipbarra...@sapo.pt
  To: pmassico...@hotmail.com
  CC: r-help@r-project.org
  Subject: Re: [R] Histogram
 
  Hello,
 
  See the arguments 'right' and 'include.lowest' of ?hist.
  To give what you want, try instead
 
  h1 - hist(1:10, 10)  # counts are 2, 1, 1, ...
  h2 - hist(1:10, breaks = 0:10)  # all counts are 1
 
 
  and see the difference between h1 and h2, components
'breaks'
  and 'counts'.
 
  Hope this helps,
 
  Rui Barradas
 
  Em 04-09-2013 19:34, philippe massicotte escreveu:
  Hi everyone.
  I'm currently translating some Matlab code into R. However,
  I realized that the hsit function produce different results
in
  both languages.
  in Matlab, hist(1:10, 10) will produce 10 bins with a count
  of 1 in each, but in R it will produce 9 classes with count
of
  2,1,1,1,1,1,1,1,1.
  I'm a bit embarrassed to ask such question, but why R is
not
  producing 10 classes as requested?
  Thanks in advance,Phil 
 [[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.
 
   
   [[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-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] Histogram

2013-09-05 Thread Duncan Murdoch

On 05/09/2013 10:17 AM, David Carlson wrote:

I wasn't suggesting that much detail, but I think the addition
of one sentence in the last paragraph of the Details section
would make it the meaning of the number is a suggestion only
clearer.

These functions provide a suggested number of bins that may be
modified to produce 'round' breakpoints covering the range of
the values in x.


I think that's the wrong place for it (since breaks=10 is perfectly 
fine, but is not a function).  I'll change the initial sentence to say:


In the last three cases the number is a suggestion only; the
 breakpoints will be set to \code{\link{pretty}} values.

If people want to know what pretty values are, they can follow the link.

Duncan Murdoch



Added just before the last sentence, Alternatively, . . .

Also pretty() could be added to the See Also section.


David Carlson

-Original Message-
From: Duncan Murdoch [mailto:murdoch.dun...@gmail.com]
Sent: Wednesday, September 4, 2013 7:00 PM
To: dcarl...@tamu.edu
Cc: 'philippe massicotte'; 'Rui Barradas';
'r-help@R-project.org'
Subject: Re: [R] Histogram

On 13-09-04 4:44 PM, David Carlson wrote: Good question. It
turns out
that the manual page does not tell
   the whole story.

Do you really think the manual page would be improved if it went
into as
much detail as you give below?  It does say clearly that breaks
is a
suggestion only.  I don't think it would be clearer if it
explained
exactly how the suggestion is used. It would just be more
complicated,
and less likely to be read.

Duncan Murdoch


   Looking at the source code for hist.default,
   the function starts with the number of breaks suggested by
   nclass.Sturges(), but then this number (or any other number
of
   breaks that you specify) is passed to pretty() along with the
   maximum and the minimum values of the data (ie range(data))
to
   create pretty break intervals. In your example,
   nclass.Sturges() always recommends 8 breaks, but the number
of
   the breaks changes based on the minimum and maximum values.
So
   the only way to get exactly the number of breaks you want is
to
   specify the break intervals yourself.
  
   David Carlson
  
  
   -Original Message-
   From: r-help-boun...@r-project.org
   [mailto:r-help-boun...@r-project.org] On Behalf Of philippe
   massicotte
   Sent: Wednesday, September 4, 2013 3:02 PM
   To: Rui Barradas
   Cc: r-help@R-project.org
   Subject: Re: [R] Histogram
  
   Thank you everyone.
   Try executing this:
   replicate(100, length(hist(rnorm(100), nclass = 10)$counts))
   I'm still not sure why the number of bins (classes) is not
   consistent.
   Thank in advance.
  
   Date: Wed, 4 Sep 2013 20:27:36 +0100
   From: ruipbarra...@sapo.pt
   To: pmassico...@hotmail.com
   CC: r-help@r-project.org
   Subject: Re: [R] Histogram
  
   Hello,
  
   See the arguments 'right' and 'include.lowest' of ?hist.
   To give what you want, try instead
  
   h1 - hist(1:10, 10)  # counts are 2, 1, 1, ...
   h2 - hist(1:10, breaks = 0:10)  # all counts are 1
  
  
   and see the difference between h1 and h2, components
'breaks'
   and 'counts'.
  
   Hope this helps,
  
   Rui Barradas
  
   Em 04-09-2013 19:34, philippe massicotte escreveu:
   Hi everyone.
   I'm currently translating some Matlab code into R. However,
   I realized that the hsit function produce different results
in
   both languages.
   in Matlab, hist(1:10, 10) will produce 10 bins with a count
   of 1 in each, but in R it will produce 9 classes with count
of
   2,1,1,1,1,1,1,1,1.
   I'm a bit embarrassed to ask such question, but why R is
not
   producing 10 classes as requested?
   Thanks in advance,Phil   
[[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.
  

[[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-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

[R] Histogram

2013-09-04 Thread philippe massicotte
Hi everyone.
I'm currently translating some Matlab code into R. However, I realized that the 
hsit function produce different results in both languages.
in Matlab, hist(1:10, 10) will produce 10 bins with a count of 1 in each, but 
in R it will produce 9 classes with count of 2,1,1,1,1,1,1,1,1.
I'm a bit embarrassed to ask such question, but why R is not producing 10 
classes as requested?
Thanks in advance,Phil
[[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] Histogram

2013-09-04 Thread David Carlson
We can just ask hist():

? hist

. . . 

breaks  

one of:

a vector giving the breakpoints between histogram cells,

a function to compute the vector of breakpoints,

a single number giving the number of cells for the
histogram,

=
a character string naming an algorithm to compute the number
of cells (see 'Details'),

a function to compute the number of cells.

In the last three cases the number is a suggestion only.


In this case hist has decided to ignore you. You can overrule by
specifying the breaks:

hist(1:10, 0:10+.5)

-
David L Carlson
Associate Professor of Anthropology
Texas AM University
College Station, TX 77840-4352





-Original Message-
From: r-help-boun...@r-project.org
[mailto:r-help-boun...@r-project.org] On Behalf Of philippe
massicotte
Sent: Wednesday, September 4, 2013 1:34 PM
To: r-help@R-project.org
Subject: [R] Histogram

Hi everyone.
I'm currently translating some Matlab code into R. However, I
realized that the hsit function produce different results in
both languages.
in Matlab, hist(1:10, 10) will produce 10 bins with a count of 1
in each, but in R it will produce 9 classes with count of
2,1,1,1,1,1,1,1,1.
I'm a bit embarrassed to ask such question, but why R is not
producing 10 classes as requested?
Thanks in advance,Phil
[[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-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] Histogram

2013-09-04 Thread Rui Barradas

Hello,

See the arguments 'right' and 'include.lowest' of ?hist.
To give what you want, try instead

h1 - hist(1:10, 10)  # counts are 2, 1, 1, ...
h2 - hist(1:10, breaks = 0:10)  # all counts are 1


and see the difference between h1 and h2, components 'breaks' and 'counts'.

Hope this helps,

Rui Barradas

Em 04-09-2013 19:34, philippe massicotte escreveu:

Hi everyone.
I'm currently translating some Matlab code into R. However, I realized that the 
hsit function produce different results in both languages.
in Matlab, hist(1:10, 10) will produce 10 bins with a count of 1 in each, but 
in R it will produce 9 classes with count of 2,1,1,1,1,1,1,1,1.
I'm a bit embarrassed to ask such question, but why R is not producing 10 
classes as requested?
Thanks in advance,Phil  
[[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-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] Histogram

2013-09-04 Thread Duncan Murdoch

On 04/09/2013 4:02 PM, philippe massicotte wrote:

Thank you everyone.
Try executing this:
replicate(100, length(hist(rnorm(100), nclass = 10)$counts))
I'm still not sure why the number of bins (classes) is not consistent.


R is behaving as documented.  You suggested 10 bins, but it finds for 
some datasets that a smaller or larger number gives better results.  If 
you really want exactly 10 bins, then specify where you want them.


Duncan Murdoch

Thank in advance.

 Date: Wed, 4 Sep 2013 20:27:36 +0100
 From: ruipbarra...@sapo.pt
 To: pmassico...@hotmail.com
 CC: r-help@r-project.org
 Subject: Re: [R] Histogram

 Hello,

 See the arguments 'right' and 'include.lowest' of ?hist.
 To give what you want, try instead

 h1 - hist(1:10, 10)  # counts are 2, 1, 1, ...
 h2 - hist(1:10, breaks = 0:10)  # all counts are 1


 and see the difference between h1 and h2, components 'breaks' and 'counts'.

 Hope this helps,

 Rui Barradas

 Em 04-09-2013 19:34, philippe massicotte escreveu:
  Hi everyone.
  I'm currently translating some Matlab code into R. However, I realized that 
the hsit function produce different results in both languages.
  in Matlab, hist(1:10, 10) will produce 10 bins with a count of 1 in each, 
but in R it will produce 9 classes with count of 2,1,1,1,1,1,1,1,1.
  I'm a bit embarrassed to ask such question, but why R is not producing 10 
classes as requested?
  Thanks in advance,Phil
[[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.
 

[[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-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] Histogram

2013-09-04 Thread Ista Zahn
On Wed, Sep 4, 2013 at 4:02 PM, philippe massicotte
pmassico...@hotmail.com wrote:
 Thank you everyone.
 Try executing this:
 replicate(100, length(hist(rnorm(100), nclass = 10)$counts))
 I'm still not sure why the number of bins (classes) is not consistent.

It depends on the range of x. If you look at the definition of the
hist function (just type hist.default at the prompt) you will find
that when breaks are specified as a single number they are calculated
using

pretty(range(x), n = breaks)

see ?pretty for details.

Best,
Ista

 Thank in advance.

 Date: Wed, 4 Sep 2013 20:27:36 +0100
 From: ruipbarra...@sapo.pt
 To: pmassico...@hotmail.com
 CC: r-help@r-project.org
 Subject: Re: [R] Histogram

 Hello,

 See the arguments 'right' and 'include.lowest' of ?hist.
 To give what you want, try instead

 h1 - hist(1:10, 10)  # counts are 2, 1, 1, ...
 h2 - hist(1:10, breaks = 0:10)  # all counts are 1


 and see the difference between h1 and h2, components 'breaks' and 'counts'.

 Hope this helps,

 Rui Barradas

 Em 04-09-2013 19:34, philippe massicotte escreveu:
  Hi everyone.
  I'm currently translating some Matlab code into R. However, I realized 
  that the hsit function produce different results in both languages.
  in Matlab, hist(1:10, 10) will produce 10 bins with a count of 1 in each, 
  but in R it will produce 9 classes with count of 2,1,1,1,1,1,1,1,1.
  I'm a bit embarrassed to ask such question, but why R is not producing 10 
  classes as requested?
  Thanks in advance,Phil
  [[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.
 

 [[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-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] Histogram

2013-09-04 Thread arun
Hi,
replicate(100,length(hist(10,0:10)$counts))
#  [1] 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 
10
 #[26] 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 
10
 #[51] 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 
10
 #[76] 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 
10


 set.seed(56)
 a1- rnorm(100)
 bins- seq(min(a1),max(a1)+1,by=0.2)
 replicate(100,length(hist(a1,breaks=bins)$counts))
 # [1] 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 
29
 #[26] 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 
29
 #[51] 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 
29
 #[76] 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 
29


#May be this is what you are looking for:

library(Rlab)
set.seed(56)
 replicate(100,length(hplot(rnorm(100),nclass=10)$counts))
#  [1] 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 
10
 #[26] 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 
10
 #[51] 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 
10
 #[76] 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 
10


A.K.




- Original Message -
From: philippe massicotte pmassico...@hotmail.com
To: Rui Barradas ruipbarra...@sapo.pt
Cc: r-help@R-project.org r-help@r-project.org
Sent: Wednesday, September 4, 2013 4:02 PM
Subject: Re: [R] Histogram

Thank you everyone.
Try executing this:
replicate(100, length(hist(rnorm(100), nclass = 10)$counts))
I'm still not sure why the number of bins (classes) is not consistent. 
Thank in advance.

 Date: Wed, 4 Sep 2013 20:27:36 +0100
 From: ruipbarra...@sapo.pt
 To: pmassico...@hotmail.com
 CC: r-help@r-project.org
 Subject: Re: [R] Histogram
 
 Hello,
 
 See the arguments 'right' and 'include.lowest' of ?hist.
 To give what you want, try instead
 
 h1 - hist(1:10, 10)  # counts are 2, 1, 1, ...
 h2 - hist(1:10, breaks = 0:10)  # all counts are 1
 
 
 and see the difference between h1 and h2, components 'breaks' and 'counts'.
 
 Hope this helps,
 
 Rui Barradas
 
 Em 04-09-2013 19:34, philippe massicotte escreveu:
  Hi everyone.
  I'm currently translating some Matlab code into R. However, I realized that 
  the hsit function produce different results in both languages.
  in Matlab, hist(1:10, 10) will produce 10 bins with a count of 1 in each, 
  but in R it will produce 9 classes with count of 2,1,1,1,1,1,1,1,1.
  I'm a bit embarrassed to ask such question, but why R is not producing 10 
  classes as requested?
  Thanks in advance,Phil                         
      [[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.
 
                          
    [[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-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] Histogram

2013-09-04 Thread David Carlson
Good question. It turns out that the manual page does not tell
the whole story. Looking at the source code for hist.default,
the function starts with the number of breaks suggested by
nclass.Sturges(), but then this number (or any other number of
breaks that you specify) is passed to pretty() along with the
maximum and the minimum values of the data (ie range(data)) to
create pretty break intervals. In your example,
nclass.Sturges() always recommends 8 breaks, but the number of
the breaks changes based on the minimum and maximum values. So
the only way to get exactly the number of breaks you want is to
specify the break intervals yourself.

David Carlson


-Original Message-
From: r-help-boun...@r-project.org
[mailto:r-help-boun...@r-project.org] On Behalf Of philippe
massicotte
Sent: Wednesday, September 4, 2013 3:02 PM
To: Rui Barradas
Cc: r-help@R-project.org
Subject: Re: [R] Histogram

Thank you everyone.
Try executing this:
replicate(100, length(hist(rnorm(100), nclass = 10)$counts))
I'm still not sure why the number of bins (classes) is not
consistent. 
Thank in advance.

 Date: Wed, 4 Sep 2013 20:27:36 +0100
 From: ruipbarra...@sapo.pt
 To: pmassico...@hotmail.com
 CC: r-help@r-project.org
 Subject: Re: [R] Histogram
 
 Hello,
 
 See the arguments 'right' and 'include.lowest' of ?hist.
 To give what you want, try instead
 
 h1 - hist(1:10, 10)  # counts are 2, 1, 1, ...
 h2 - hist(1:10, breaks = 0:10)  # all counts are 1
 
 
 and see the difference between h1 and h2, components 'breaks'
and 'counts'.
 
 Hope this helps,
 
 Rui Barradas
 
 Em 04-09-2013 19:34, philippe massicotte escreveu:
  Hi everyone.
  I'm currently translating some Matlab code into R. However,
I realized that the hsit function produce different results in
both languages.
  in Matlab, hist(1:10, 10) will produce 10 bins with a count
of 1 in each, but in R it will produce 9 classes with count of
2,1,1,1,1,1,1,1,1.
  I'm a bit embarrassed to ask such question, but why R is not
producing 10 classes as requested?
  Thanks in advance,Phil  
  [[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.
 
  
[[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-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] Histogram

2013-09-04 Thread Duncan Murdoch
On 13-09-04 4:44 PM, David Carlson wrote: Good question. It turns out 
that the manual page does not tell

 the whole story.

Do you really think the manual page would be improved if it went into as 
much detail as you give below?  It does say clearly that breaks is a 
suggestion only.  I don't think it would be clearer if it explained 
exactly how the suggestion is used. It would just be more complicated, 
and less likely to be read.


Duncan Murdoch


 Looking at the source code for hist.default,
 the function starts with the number of breaks suggested by
 nclass.Sturges(), but then this number (or any other number of
 breaks that you specify) is passed to pretty() along with the
 maximum and the minimum values of the data (ie range(data)) to
 create pretty break intervals. In your example,
 nclass.Sturges() always recommends 8 breaks, but the number of
 the breaks changes based on the minimum and maximum values. So
 the only way to get exactly the number of breaks you want is to
 specify the break intervals yourself.

 David Carlson


 -Original Message-
 From: r-help-boun...@r-project.org
 [mailto:r-help-boun...@r-project.org] On Behalf Of philippe
 massicotte
 Sent: Wednesday, September 4, 2013 3:02 PM
 To: Rui Barradas
 Cc: r-help@R-project.org
 Subject: Re: [R] Histogram

 Thank you everyone.
 Try executing this:
 replicate(100, length(hist(rnorm(100), nclass = 10)$counts))
 I'm still not sure why the number of bins (classes) is not
 consistent.
 Thank in advance.

 Date: Wed, 4 Sep 2013 20:27:36 +0100
 From: ruipbarra...@sapo.pt
 To: pmassico...@hotmail.com
 CC: r-help@r-project.org
 Subject: Re: [R] Histogram

 Hello,

 See the arguments 'right' and 'include.lowest' of ?hist.
 To give what you want, try instead

 h1 - hist(1:10, 10)  # counts are 2, 1, 1, ...
 h2 - hist(1:10, breaks = 0:10)  # all counts are 1


 and see the difference between h1 and h2, components 'breaks'
 and 'counts'.

 Hope this helps,

 Rui Barradas

 Em 04-09-2013 19:34, philippe massicotte escreveu:
 Hi everyone.
 I'm currently translating some Matlab code into R. However,
 I realized that the hsit function produce different results in
 both languages.
 in Matlab, hist(1:10, 10) will produce 10 bins with a count
 of 1 in each, but in R it will produce 9 classes with count of
 2,1,1,1,1,1,1,1,1.
 I'm a bit embarrassed to ask such question, but why R is not
 producing 10 classes as requested?
 Thanks in advance,Phil 
[[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.


[[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-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] Histogram

2013-09-04 Thread philippe massicotte
Thank you everyone for your help.


 Date: Wed, 4 Sep 2013 20:00:02 -0400
 From: murdoch.dun...@gmail.com
 To: dcarl...@tamu.edu
 CC: pmassico...@hotmail.com; ruipbarra...@sapo.pt; r-help@r-project.org
 Subject: Re: [R] Histogram
 
 On 13-09-04 4:44 PM, David Carlson wrote: Good question. It turns out 
 that the manual page does not tell
   the whole story.
 
 Do you really think the manual page would be improved if it went into as 
 much detail as you give below?  It does say clearly that breaks is a 
 suggestion only.  I don't think it would be clearer if it explained 
 exactly how the suggestion is used. It would just be more complicated, 
 and less likely to be read.
 
 Duncan Murdoch
 
 
   Looking at the source code for hist.default,
   the function starts with the number of breaks suggested by
   nclass.Sturges(), but then this number (or any other number of
   breaks that you specify) is passed to pretty() along with the
   maximum and the minimum values of the data (ie range(data)) to
   create pretty break intervals. In your example,
   nclass.Sturges() always recommends 8 breaks, but the number of
   the breaks changes based on the minimum and maximum values. So
   the only way to get exactly the number of breaks you want is to
   specify the break intervals yourself.
  
   David Carlson
  
  
   -Original Message-
   From: r-help-boun...@r-project.org
   [mailto:r-help-boun...@r-project.org] On Behalf Of philippe
   massicotte
   Sent: Wednesday, September 4, 2013 3:02 PM
   To: Rui Barradas
   Cc: r-help@R-project.org
   Subject: Re: [R] Histogram
  
   Thank you everyone.
   Try executing this:
   replicate(100, length(hist(rnorm(100), nclass = 10)$counts))
   I'm still not sure why the number of bins (classes) is not
   consistent.
   Thank in advance.
  
   Date: Wed, 4 Sep 2013 20:27:36 +0100
   From: ruipbarra...@sapo.pt
   To: pmassico...@hotmail.com
   CC: r-help@r-project.org
   Subject: Re: [R] Histogram
  
   Hello,
  
   See the arguments 'right' and 'include.lowest' of ?hist.
   To give what you want, try instead
  
   h1 - hist(1:10, 10)  # counts are 2, 1, 1, ...
   h2 - hist(1:10, breaks = 0:10)  # all counts are 1
  
  
   and see the difference between h1 and h2, components 'breaks'
   and 'counts'.
  
   Hope this helps,
  
   Rui Barradas
  
   Em 04-09-2013 19:34, philippe massicotte escreveu:
   Hi everyone.
   I'm currently translating some Matlab code into R. However,
   I realized that the hsit function produce different results in
   both languages.
   in Matlab, hist(1:10, 10) will produce 10 bins with a count
   of 1 in each, but in R it will produce 9 classes with count of
   2,1,1,1,1,1,1,1,1.
   I'm a bit embarrassed to ask such question, but why R is not
   producing 10 classes as requested?
   Thanks in advance,Phil   
[[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.
  
  
  [[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-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] histogram with bars colored according to a vector of values

2013-07-26 Thread Jim Lemon

On 07/26/2013 12:13 PM, john d wrote:

Dear all,

Let's say I have the following data.frame:

dat-data.frame(x=rnorm(100), y=rnorm(100,2))

and I plot a histogram of variable x, somethink like:
hist(dat$x, breaks=-5:5)

Now, I'd like to color each bar according to the mean of the cases
according to y. For instance, the color of the bar between -2 and -1 should
reflect the mean of variable y for the corresponding cases. Any suggestions?

John


Hi John,
Try this:

dat$xcut-cut(dat$x,breaks=-5:5)
library(plotrix)
barcol-color.scale(by(dat$y,dat$xcut,mean),extremes=c(red,blue))
hist(dat$x,breaks=-5:5,col=barcol)

Jim

__
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] histogram with bars colored according to a vector of values

2013-07-25 Thread john d
Dear all,

Let's say I have the following data.frame:

dat-data.frame(x=rnorm(100), y=rnorm(100,2))

and I plot a histogram of variable x, somethink like:
hist(dat$x, breaks=-5:5)

Now, I'd like to color each bar according to the mean of the cases
according to y. For instance, the color of the bar between -2 and -1 should
reflect the mean of variable y for the corresponding cases. Any suggestions?

John

[[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] Histogram equalization of dataset

2013-03-20 Thread SpaceSeller
I read about histogram equalization of dataset. It is commonly used for image
data. It is written: Each variable in dataset is assigned to one bin. Then,
each variable in the dataset is assigned to one bin, incrementing the value
of that bin by one. Then, a cumulative histogram is created by adding to
each bin the value of its preceding bins. Finaly, the value of each bin is
divided by the total number of observations, thus standardizing the data
within the interval of [0,1].

Could you show me how to get it?
If a have  a dataset below:
  X1
X2
Min.   :-4.37371   Min.   :-27.84627   
 1st Qu.:-0.205581st Qu.:  0.0  
 Median :-0.01528  Median :  0.07848
 Mean   :-0.04896   Mean   :  0.02751  
 3rd Qu.: 0.14511  3rd Qu.:  0.28831   
 Max.   : 0.78047   Max.   :  0.89851   



--
View this message in context: 
http://r.789695.n4.nabble.com/Histogram-equalization-of-dataset-tp4661887.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] histogram

2013-03-05 Thread arun
HI Elisa,
Just noticed the order of elements in vec1:
You have to replace `vec1`
dat2- as.dist(dat1[,-1],upper=F,diag=F) 
vec1- as.vector(dat2)
 head(vec1)
#[1]  5.796656 43.523023 38.193750 44.730182  6.511703  2.904954 #the order is 
based on columns

#with
dat1- read.csv(rightest.csv,sep=,,header=TRUE,check.names=FALSE) 
label1=c(0-25,25-50,50-75)
dat1New- dat1[,-1]
vec1- unlist(lapply(seq_len(nrow(dat1New)),function(i) 
dat1New[i,][1:which(dat1New[i,]==0)-1]))
 head(vec1)
#    1 1 2 1 2 3 
# 5.796656 43.523023 36.305633 38.193750 31.623020  5.391179  #correct order
 dat1[1:4,1:4]
#  St. 1 2 3
#1   1  0.00  5.796656 43.523023
#2   2  5.796656  0.00 36.305633
#3   3 43.523023 36.305633  0.00
#4   4 38.193750 31.623020  5.391179

Name2-unlist(lapply(0:123,function(i) if(length(rep(i+1,i)=1)) 
paste((,paste(rep(i+1,i)[1],seq_along(rep(i+1,i)),sep=,),),sep=) else 
NULL)) 
dat3New- data.frame(Name2,vec1) 
resNew-t(aggregate(.~Name2,data=dat3New,function(x) 
table(cut(x,breaks=seq(0,75,25),labels=label1 
colnames(resNew)- resNew[1,] 
resNew1- resNew[-1,] 
row.names(resNew1)-gsub(vec1.,,row.names(resNew1)) 
Names3-apply(resNew1,1,function(x) paste(names(which(x!=0)),collapse=,)) 
res2- data.frame(Frequency=apply(resNew1,1,function(x) sum(1*(x!=0))), 
stations=Names3,stringsAsFactors=FALSE)

A.K.






- Original Message -
From: arun smartpink...@yahoo.com
To: eliza botto eliza_bo...@hotmail.com
Cc: 
Sent: Tuesday, March 5, 2013 8:12 AM
Subject: Re: histogram

Dear Elisa,
I already sent you the solution.


 Name2-unlist(lapply(0:123,function(i) 
if(length(rep(i+1,i)=1)) 
paste((,paste(rep(i+1,i)[1],seq_along(rep(i+1,i)),sep=,),),sep=)
else NULL))
dat3New- data.frame(Name2,vec1)
resNew-t(aggregate(.~Name2,data=dat3New,function(x) 
table(cut(x,breaks=seq(0,75,25),labels=label1
colnames(resNew)- resNew[1,]
resNew1- resNew[-1,]
row.names(resNew1)-gsub(vec1.,,row.names(resNew1))
Names3-apply(resNew1,1,function(x) paste(names(which(x!=0)),collapse=,)) 
res2- data.frame(Frequency=apply(resNew1,1,function(x) sum(1*(x!=0))), 
stations=Names3,stringsAsFactors=FALSE)
A.K.


From: eliza botto eliza_bo...@hotmail.com
To: smartpink...@yahoo.com smartpink...@yahoo.com 
Sent: Tuesday, March 5, 2013 7:04 AM
Subject: RE: histogram



Dear Arun,
Extremely sorry for replying you late. i really wanted to calculate the index 
of dat3. It alright for me, even if the size of output is really large.
thanks in advance

Elisa

__
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] histogram

2013-03-05 Thread arun


Hi,

I guess this is what you wanted.
Attaching a plot from a subset (lstSub)



dat1- read.csv(rightest.csv,sep=,,header=TRUE,check.names=FALSE) 
label1=c(0-25,25-50,50-75) 
Name1-unlist(lapply(0:123,function(i) rep(i+1,i))) 
dat1New- dat1[,-1]
vec1- unlist(lapply(seq_len(nrow(dat1New)),function(i) 
dat1New[i,][1:which(dat1New[i,]==0)-1]))
dat3-data.frame(Name1,vec1)
dat3$Categ-as.character(cut(dat3$vec1,breaks=seq(0,75,25),labels=label1))
source(k.txt)
lst1- split(dat3,dat3$Name1)
#lstSub-split(dat3,dat3$Name1)[1:4]

pdf(ElisaNew0_25.pdf)
 lapply(lst1,function(x) {indx025-which(x$Categ==0-25); 
indx2550-which(x$Categ==25-50);indx5075-which(x$Categ==50-75); 
if(length(indx025)=1) 
{matplot(k[,indx025],ylim=c(0,5),type=l,col=grey,main=paste(range 
0-25,line=,unique(x$Name1),sep= ),xlab=T,ylab=Q); 
lines(k[,unique(x$Name1)],type=l,col=black)} else NULL})
dev.off()

pdf(ElisaNew25_50New.pdf)
 lapply(lst1,function(x) {indx025-which(x$Categ==0-25); 
indx2550-which(x$Categ==25-50);indx5075-which(x$Categ==50-75); 
if(length(indx2550)=1) 
{matplot(k[,indx2550],ylim=c(0,5),type=l,col=grey,main=paste(range 
25-50,line=,unique(x$Name1),sep= ),xlab=T,ylab=Q); 
lines(k[,unique(x$Name1)],type=l,col=black)} else NULL})
dev.off()

pdf(ElisaNew50_75.pdf)
 lapply(lst1,function(x) {indx025-which(x$Categ==0-25); 
indx2550-which(x$Categ==25-50);indx5075-which(x$Categ==50-75); 
if(length(indx5075)=1) 
{matplot(k[,indx5075],ylim=c(0,5),type=l,col=grey,main=paste(range 
50-75,line=,unique(x$Name1),sep= ),xlab=T,ylab=Q); 
lines(k[,unique(x$Name1)],type=l,col=black)} else NULL})
dev.off()


A.K.




From: eliza botto eliza_bo...@hotmail.com
To: smartpink...@yahoo.com smartpink...@yahoo.com 
Sent: Tuesday, March 5, 2013 5:04 PM
Subject: RE: histogram



Dear Arun,
Thanks for the update.
Any success with the recently asked question?
thanks


elisa


 Date: Tue, 5 Mar 2013 14:00:29 -0800
 From: smartpink...@yahoo.com
 Subject: Re: histogram
 To: eliza_bo...@hotmail.com
 CC: r-help@r-project.org
 
 HI Elisa,
 Just noticed the order of elements in vec1:
 You have to replace `vec1`
 dat2- as.dist(dat1[,-1],upper=F,diag=F) 
 vec1- as.vector(dat2)
  head(vec1)
 #[1]  5.796656 43.523023 38.193750 44.730182  6.511703  2.904954 #the order 
 is based on columns
 
 #with
 dat1- read.csv(rightest.csv,sep=,,header=TRUE,check.names=FALSE) 
 label1=c(0-25,25-50,50-75)
 dat1New- dat1[,-1]
 vec1- unlist(lapply(seq_len(nrow(dat1New)),function(i) 
 dat1New[i,][1:which(dat1New[i,]==0)-1]))
  head(vec1)
 #    1 1 2 1 2 3 
 # 5.796656 43.523023 36.305633 38.193750 31.623020  5.391179  #correct order
  dat1[1:4,1:4]
 #  St. 1 2 3
 #1   1  0.00  5.796656 43.523023
 #2   2  5.796656  0.00 36.305633
 #3   3 43.523023 36.305633  0.00
 #4   4 38.193750 31.623020  5.391179
 
 Name2-unlist(lapply(0:123,function(i) if(length(rep(i+1,i)=1)) 
 paste((,paste(rep(i+1,i)[1],seq_along(rep(i+1,i)),sep=,),),sep=) else 
 NULL)) 
 dat3New- data.frame(Name2,vec1) 
 resNew-t(aggregate(.~Name2,data=dat3New,function(x) 
 table(cut(x,breaks=seq(0,75,25),labels=label1 
 colnames(resNew)- resNew[1,] 
 resNew1- resNew[-1,] 
 row.names(resNew1)-gsub(vec1.,,row.names(resNew1)) 
 Names3-apply(resNew1,1,function(x) paste(names(which(x!=0)),collapse=,)) 
 res2- data.frame(Frequency=apply(resNew1,1,function(x) sum(1*(x!=0))), 
 stations=Names3,stringsAsFactors=FALSE)
 
 A.K.
 
 
 
 
 
 
 - Original Message -
 From: arun smartpink...@yahoo.com
 To: eliza botto eliza_bo...@hotmail.com
 Cc: 
 Sent: Tuesday, March 5, 2013 8:12 AM
 Subject: Re: histogram
 
 Dear Elisa,
 I already sent you the solution.
 
 
  Name2-unlist(lapply(0:123,function(i) 
 if(length(rep(i+1,i)=1)) 
 paste((,paste(rep(i+1,i)[1],seq_along(rep(i+1,i)),sep=,),),sep=)
 else NULL))
 dat3New- data.frame(Name2,vec1)
 resNew-t(aggregate(.~Name2,data=dat3New,function(x) 
 table(cut(x,breaks=seq(0,75,25),labels=label1
 colnames(resNew)- resNew[1,]
 resNew1- resNew[-1,]
 row.names(resNew1)-gsub(vec1.,,row.names(resNew1))
 Names3-apply(resNew1,1,function(x) paste(names(which(x!=0)),collapse=,)) 
 res2- data.frame(Frequency=apply(resNew1,1,function(x) sum(1*(x!=0))), 
 stations=Names3,stringsAsFactors=FALSE)
 A.K.
 
 
 From: eliza botto eliza_bo...@hotmail.com
 To: smartpink...@yahoo.com smartpink...@yahoo.com 
 Sent: Tuesday, March 5, 2013 7:04 AM
 Subject: RE: histogram
 
 
 
 Dear Arun,
 Extremely sorry for replying you late. i really wanted to calculate the index 
 of dat3. It alright for me, even if the size of output is really large.
 thanks in advance
 
 Elisa

ElisaNew25_50.pdf
Description: Adobe PDF document
__
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, 

Re: [R] histogram

2013-03-04 Thread arun
Hi Elisa,

I am not sure about the output you wanted.
dat1- read.csv(rightest.csv,sep=,,header=TRUE,check.names=FALSE)
 dat2- as.dist(dat1[,-1],upper=F,diag=F)
vec1- as.vector(dat2)
label1=c(0-25,25-50,50-75)
Count1- as.data.frame(table(cut(vec1,breaks=seq(0,75,25),labels=label1))) 
#Overall count
 Count1
#   Var1 Freq
#1  0-25 5465
#2 25-50 1992
#3 50-75  169


Name1-unlist(lapply(0:123,function(i) rep(i+1,i)))
 length(Name1)
#[1] 7626
dat3-data.frame(Name1,vec1)
res-t(aggregate(.~Name1,data=dat3,function(x) 
table(cut(x,breaks=seq(0,75,25),labels=label1
colnames(res)- res[1,]
 res1- res[-1,]
row.names(res1)-gsub(vec1.,,row.names(res1))
res1
#  2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#0-25  1 0 2 0 2 3 2 1  1  1  3  1  1  3  2  3  6  3  5  2  4  8 13 21 21 23 20
#25-50 0 2 1 4 3 3 5 7  8  8  8 11 12 11 13 12 11 15 14 18 17 12 10  3  2  3  6
#50-75 0 0 0 0 0 0 0 0  0  1  0  0  0  0  0  1  0  0  0  0  0  2  0  0  2  0  1
-

A.K.






Fr

istogram



Dear Arun,

i have a distance matrix as attached in excel file with this email. You can 
read the data via R and 
after reading the data i want you to extract the lower part of distance matrix 
by 
as.dist(x, upper=F, diag=F). You will see that there 
are 124 stations in my study. After that, i want to divide the data into three 
intervals 0-25, 25-75, 
75-100. Then i want to count the number of stations falling in each interval, 
which will be called 
Frequency. After that i want to draw the following table
Range     stations  
   Frequency
0-25   names of station 
     Number of stations
25-50  
50-75
Finally, i want to draw histogram. i know i asked same kind of question before, 
but those commands are not working on distance matrix.

thankyou very very much in advance
elisa

__
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] histogram

2013-03-04 Thread arun
Hi,
Sorry, I forgot names(which()
Names2-apply(res1,1,function(x) paste(names(which(x!=0)),collapse=,))

res2- data.frame(Frequency=apply(res1,1,function(x) sum(1*(x!=0))), 
stations=Names2,stringsAsFactors=FALSE)
 res2
 #     Frequency
#0-25    121
#25-50   122
#50-75    76




 #stations
#0-25    
#2,4,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124
#25-50 
#3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124
#50-75  
    
#11,17,23,26,28,31,32,34,35,36,37,38,39,40,41,42,48,49,51,54,57,59,60,62,65,66,69,70,71,74,76,77,78,79,80,81,82,83,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,122,124


A.K.



- Original Message -
From: arun smartpink...@yahoo.com
To: eliza botto eliza_bo...@hotmail.com
Cc: R help r-help@r-project.org
Sent: Monday, March 4, 2013 3:26 PM
Subject: Re: histogram

Hi,

dat1- read.csv(rightest.csv,sep=,,header=TRUE,check.names=FALSE)
 dat2- as.dist(dat1[,-1],upper=F,diag=F)
vec1- as.vector(dat2)
label1=c(0-25,25-50,50-75)
Name1-unlist(lapply(0:123,function(i) rep(i+1,i)))
dat3-data.frame(Name1,vec1)
res-t(aggregate(.~Name1,data=dat3,function(x) 
table(cut(x,breaks=seq(0,75,25),labels=label1
colnames(res)- res[1,]
res1- res[-1,]
row.names(res1)-gsub(vec1.,,row.names(res1))
res1
Names2-apply(res1,1,function(x) paste(which(x!=0),collapse=,))
res2- data.frame(Frequency=apply(res1,1,function(x) sum(1*(x!=0))), 
stations=Names2,stringsAsFactors=FALSE)

res2
#  Frequency
#0-25    121
#25-50   122
#50-75    76




   #stations
#0-25    
#1,3,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123
#25-50 
#2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123
#50-75  
   
#10,16,22,25,27,30,31,33,34,35,36,37,38,39,40,41,47,48,50,53,56,58,59,61,64,65,68,69,70,73,75,76,77,78,79,80,81,82,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,121,123

A.K.


From: eliza botto eliza_bo...@hotmail.com
To: smartpink...@yahoo.com smartpink...@yahoo.com 
Sent: Monday, March 4, 2013 3:21 PM
Subject: RE: histogram



Dear Arun,


Thanks for replying
Although codes well defined my problem but the table in the end should look 
like the following

its just an imaginary table.
Range                          stations                                         
Frequency
0-25                           1,2,3,8,9                                        
   5
25-50                      4,10,11,100                                      
   4
50-75                          55,56,57                          

Re: [R] histogram

2013-03-04 Thread arun
Hi,

dat1- read.csv(rightest.csv,sep=,,header=TRUE,check.names=FALSE)
 dat2- as.dist(dat1[,-1],upper=F,diag=F)
vec1- as.vector(dat2)
label1=c(0-25,25-50,50-75)
Name1-unlist(lapply(0:123,function(i) rep(i+1,i)))
dat3-data.frame(Name1,vec1)
res-t(aggregate(.~Name1,data=dat3,function(x) 
table(cut(x,breaks=seq(0,75,25),labels=label1
colnames(res)- res[1,]
res1- res[-1,]
row.names(res1)-gsub(vec1.,,row.names(res1))
res1
Names2-apply(res1,1,function(x) paste(which(x!=0),collapse=,))
res2- data.frame(Frequency=apply(res1,1,function(x) sum(1*(x!=0))), 
stations=Names2,stringsAsFactors=FALSE)

res2
#  Frequency
#0-25    121
#25-50   122
#50-75    76




   #stations
#0-25    
#1,3,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123
#25-50 
#2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123
#50-75  
   
#10,16,22,25,27,30,31,33,34,35,36,37,38,39,40,41,47,48,50,53,56,58,59,61,64,65,68,69,70,73,75,76,77,78,79,80,81,82,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,121,123

A.K.


From: eliza botto eliza_bo...@hotmail.com
To: smartpink...@yahoo.com smartpink...@yahoo.com 
Sent: Monday, March 4, 2013 3:21 PM
Subject: RE: histogram



Dear Arun,


Thanks for replying
Although codes well defined my problem but the table in the end should look 
like the following

its just an imaginary table.
Range                          stations                                         
Frequency
0-25                           1,2,3,8,9                                        
   5
25-50                      4,10,11,100                                      
   4
50-75                          55,56,57                                         
   3
Where the station column shows the stations where distance of station is 
between the corresponding range like 1,2,3,8,9 have the distance between 
0-25

i hope you wont mind

elisa




 Date: Mon, 4 Mar 2013 11:56:43 -0800
 From: smartpink...@yahoo.com
 Subject: Re: histogram
 To: eliza_bo...@hotmail.com
 CC: r-help@r-project.org
 
 Hi Elisa,
 
 I am not sure about the output you wanted.
 dat1- read.csv(rightest.csv,sep=,,header=TRUE,check.names=FALSE)
  dat2- as.dist(dat1[,-1],upper=F,diag=F)
 vec1- as.vector(dat2)
 label1=c(0-25,25-50,50-75)
 Count1- as.data.frame(table(cut(vec1,breaks=seq(0,75,25),labels=label1))) 
 #Overall count
  Count1
 #   Var1 Freq
 #1  0-25 5465
 #2 25-50 1992
 #3 50-75  169
 
 
 Name1-unlist(lapply(0:123,function(i) rep(i+1,i)))
  length(Name1)
 #[1] 7626
 dat3-data.frame(Name1,vec1)
 res-t(aggregate(.~Name1,data=dat3,function(x) 
 table(cut(x,breaks=seq(0,75,25),labels=label1
 colnames(res)- res[1,]
  res1- res[-1,]
 row.names(res1)-gsub(vec1.,,row.names(res1))
 res1
 #  2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 
 28
 #0-25  1 0 2 0 2 3 2 1  1  1  3  1  1  3  2  3  6  3  5  2  4  8 13 21 21 23 
 20
 #25-50 0 2 1 4 3 3 5 7  8  8  8 11 12 11 13 12 11 15 14 18 17 12 10  3  2  3  
 6
 #50-75 0 0 0 0 0 0 0 0  0  1  0  0  0  0  0  1  0  0  0  0  0  2  0  0  2  0  
 1
 -
 
 A.K.
 
 
 
 
 
 
 From: eliza botto eliza_bo...@hotmail.com
 To: smartpink...@yahoo.com smartpink...@yahoo.com 
 Sent: Monday, March 4, 2013 11:36 AM
 Subject: histogram
 
 
 
 Dear Arun,
 
 i have a distance matrix as attached in excel file with this email. You can 
 read the data via R and 
 after reading the data i want you to extract the lower part of distance 
 matrix by 
 as.dist(x, upper=F, diag=F). You will see that there 
 are 124 stations in my study. After that, i want to divide the data into 
 three intervals 0-25, 25-75, 
 75-100. Then i 

Re: [R] histogram

2013-03-04 Thread arun
Hi,

If you meant to get the array index from `res1`, then this will do it.  But, if 
it is from 'dat3`, it will  be huge as each index is unique.
indx-which(apply(res1,1,function(x) x!=0) ,arr.ind=TRUE)
 Names2-do.call(rbind,lapply(1:3,function(i) {x-indx[indx[,2]==i,]; 
paste(apply(x,1,function(y) 
paste((,paste(y,collapse=,),),sep=)),collapse=,)} ))
 res2- data.frame(Frequency=apply(res1,1,function(x) sum(1*(x!=0))), 
stations=Names2,stringsAsFactors=FALSE)

A.K.








From: eliza botto eliza_bo...@hotmail.com
To: smartpink...@yahoo.com smartpink...@yahoo.com 
Sent: Monday, March 4, 2013 5:50 PM
Subject: RE: histogram



Dear Arun,
Just a small inquiry i have.
you can see that in the results, there are some stations which are repeating 
themselves like station number 16 which is included in all three ranges. its 
because for station 16 there are over 100 values. So to get rid of 
it what if instead of stations, i want  to locate the 
coordinates of each station in the final table. like for coordinate 
(17row,16col), it should be in range 0-25 and (18row,17col) should be included 
in range 25-50.

so my final table should look like

 Range                          stations                                        
 Frequency
0-25                           (1,4),(2,3),(8,9)                                
     3
25-50                         (4,10),(11,100)                                   
   2
50-75                         (55,56),(57,60)                                   
  2       

is it possible?
thanks alot...

elisa


 Date: Mon, 4 Mar 2013 12:38:22 -0800
 From: smartpink...@yahoo.com
 Subject: Re: histogram
 To: eliza_bo...@hotmail.com
 
 Sometimes, you make mistake when you are quick.  I forgot names(which(..)). 
 THe corrected version is sent.
 Thanks.
 Arun
 
 
 
 
 
 
 
 From: eliza botto eliza_bo...@hotmail.com
 To: smartpink...@yahoo.com smartpink...@yahoo.com 
 Sent: Monday, March 4, 2013 3:31 PM
 Subject: RE: histogram
 
 
 
 My GOD, you are so quick. 
 Thankyou so very much indeed...
 stay blessed.
 
 elisa
 
 
  Date: Mon, 4 Mar 2013 12:26:44 -0800
  From: smartpink...@yahoo.com
  Subject: Re: histogram
  To: eliza_bo...@hotmail.com
  CC: r-help@r-project.org
  
  Hi,
  
  dat1- read.csv(rightest.csv,sep=,,header=TRUE,check.names=FALSE)
   dat2- as.dist(dat1[,-1],upper=F,diag=F)
  vec1- as.vector(dat2)
  label1=c(0-25,25-50,50-75)
  Name1-unlist(lapply(0:123,function(i) rep(i+1,i)))
  dat3-data.frame(Name1,vec1)
  res-t(aggregate(.~Name1,data=dat3,function(x) 
  table(cut(x,breaks=seq(0,75,25),labels=label1
  colnames(res)- res[1,]
  res1- res[-1,]
  row.names(res1)-gsub(vec1.,,row.names(res1))
  res1
  Names2-apply(res1,1,function(x) paste(which(x!=0),collapse=,))
  res2- data.frame(Frequency=apply(res1,1,function(x) sum(1*(x!=0))), 
  stations=Names2,stringsAsFactors=FALSE)
  
  res2
  #  Frequency
  #0-25    121
  #25-50   122
  #50-75    76
  
  
  
  
     
  #stations
  #0-25    
  #1,3,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123
  #25-50 
  #2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123
  #50-75  
     
  #10,16,22,25,27,30,31,33,34,35,36,37,38,39,40,41,47,48,50,53,56,58,59,61,64,65,68,69,70,73,75,76,77,78,79,80,81,82,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,121,123
  
  A.K.
  
  
  From: eliza botto eliza_bo...@hotmail.com
  To: smartpink...@yahoo.com smartpink...@yahoo.com 
  Sent: Monday, March 4, 2013 3:21 PM
  Subject: RE: histogram
  
  
  
  Dear Arun,
  
  
  Thanks for replying
  Although codes well defined my problem but the table in the end should look 
  like the following
  
  its just an 

Re: [R] histogram

2013-02-17 Thread arun
HI Elisa,
You could use ?cut()


vec1-c(33,18,13,47,30,10,6,21,39,25,40,29,14,16,44,1,41,4,15,20,46,32,38,5,31,12,48,27,36,24,34,2,35,11,42,9,8,7,26,22,43,17,19,28,23,3,49,37,50,45)
label1-unlist(lapply(mapply(c,lapply(seq(0,45,5),function(x) 
x),lapply(seq(5,50,5),function(x) x),SIMPLIFY=FALSE),function(i) 
paste(i[1],x=,i[2],sep=)))

 Count1-as.data.frame(table(cut(vec1,breaks=seq(0,50,5),labels=label1)))


 Count1
#   Var1 Freq
#1    0x=5    5
#2   5x=10    5
#3  10x=15    5
#4  15x=20    5
#5  20x=25    5
#6  25x=30    5
#7  30x=35    5
#8  35x=40    5
#9  40x=45    5
#10 45x=50    5
hist(vec1,breaks=seq(0,50,5),freq=T)

 hist(vec1,breaks=seq(0,50,5),prob=TRUE)
 lines(density(vec1))

label2-unlist(lapply(mapply(c,lapply(seq(0,45,5),function(x) 
x),lapply(seq(55,by=50,length.out=10),function(x) 
x),SIMPLIFY=FALSE),function(i) paste(i[1],x=,i[2],sep=)))
 
count2-as.data.frame(table(cut(vec1,breaks=c(0,55,100,145,190,235,280,325,370,415,460),labels=label2)))
count2
#    Var1 Freq
#1    0x=55   50
#2   5x=105    0
#3  10x=155    0
#4  15x=205    0
#5  20x=255    0
#6  25x=305    0
#7  30x=355    0
#8  35x=405    0
#9  40x=455    0
#10 45x=505    0

hist(vec1,breaks=c(0,55,100,145,190,235,280,325,370,415,460))
 hist(vec1,breaks=c(0,55,100,145,190,235,280,325,370,415,460),prob=TRUE)
 lines(density(vec1))

A.K.

From: eliza botto eliza_bo...@hotmail.com
To: smartpink...@yahoo.com smartpink...@yahoo.com 
Sent: Sunday, February 17, 2013 2:35 PM
Subject: histogram



Dear Arun,
[text file is attached in case format of email is changed]
For the following data set
33 18 13 47 30 10  6 21 39 25 40 29 14 16 44  1 41  4 15 20 46 32 38  5 31 12 
48 27 36 24 34  2 35 11 42  9  8  7 26 22 43 17 19 28 23  3 49 37 50 45

1. i first of all want to make classes in the following form

class

0x=5
5x=10
10x=15
15x=20
.
...
...
...
45x=50

and then i want to count the number of elements in each class and ultimately i 
want to execute a table in the following form

classnumber of elements in each class

0x=55
5x=105
10x=155
15x=205
.
...
...
...
45x=505

the command which i used is to count the number of elements in each class was

 length(which(x  45  x = 50))

2. is there a loop command which can count the number of elements in each range 
instead of using an individual command for each range?? 
3. then i want to make histogram out of that table.
4. lastly, i want to fit density curve on those histograms.

I am greatful to you in advance.

elisa

__
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] Histogram plot spacing

2013-01-15 Thread Julie Collet
Dear all,

I'd like to remove the space between the x-axis and the 0 of the y-axis in the 
hist function.
I saw the previous post 
https://stat.ethz.ch/pipermail/r-help/2012-September/324177.html suggesting 
adding the x-axis at position 0 (or the lowest value of y) after making the 
histogram. Unfortunately, it doesn't work in my case as I want to use it with a 
histogram with a ylim starting above 0, so that the x-axis ends up superposing 
the histogram bars. Any suggestion?

For info, I've been using:
hist(univariateCV$varcomp, ylim=c(10300,11100), xlim=c(-0.002,0.40), 
breaks=seq(0,1,0.004), axes=FALSE, main=, ylab=, xlab=,col='blue', 
xaxt=n)
axis(1, at=seq(0,0.40,0.05), labels=seq(0,0.40,0.05), pos=10300)
which gives the x axis superposed with the histogram bars.

Many thanks
Julie

[[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] Histogram plot spacing

2013-01-15 Thread Uwe Ligges



On 15.01.2013 12:35, Julie Collet wrote:

Dear all,

I'd like to remove the space between the x-axis and the 0 of the y-axis in the 
hist function.
I saw the previous post 
https://stat.ethz.ch/pipermail/r-help/2012-September/324177.html suggesting 
adding the x-axis at position 0 (or the lowest value of y) after making the 
histogram. Unfortunately, it doesn't work in my case as I want to use it with a 
histogram with a ylim starting above 0, so that the x-axis ends up superposing 
the histogram bars. Any suggestion?

For info, I've been using:
hist(univariateCV$varcomp, ylim=c(10300,11100), xlim=c(-0.002,0.40), breaks=seq(0,1,0.004), axes=FALSE, 
main=, ylab=, xlab=,col='blue', xaxt=n)
axis(1, at=seq(0,0.40,0.05), labels=seq(0,0.40,0.05), pos=10300)
which gives the x axis superposed with the histogram bars.



par(yaxs=i)
hist(rnorm(100))

Uwe Ligges




Many thanks
Julie

[[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-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] Histogram plot help

2012-12-04 Thread YAddo
Thanks, Rui and David!



--
View this message in context: 
http://r.789695.n4.nabble.com/Histogram-plot-help-tp4651958p4652065.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] Histogram plot help

2012-12-03 Thread YAddo
Dear All:

I plotted a histogram with Abline, clipping with color codes but i run into
some problems.   The abline' does not show up at all,  and when i request
the 'prob=True' (to obtain the freqs), my clipped region colors the section
of the graph instead of the plot only.

Is there any way i can get the y-axis figures  to be in whole numbers rather
than decimals? 

Many thanks for your help.
YA

Here are the working codes i am tweaking.

Everything worked fine before i trying adding stuffs (prob=T, etc).


x - rnorm(1000)
hist(x, xlim=c(-4,4),ylab=Prevalence,prob=T,lwd=3,las=1)
lines(density(x),col=black,lwd=2)
usr - par(usr)
clip(usr[1], -2, usr[3], usr[4])
hist(x, col = 'red', add = TRUE)
clip(2, usr[2], usr[3], usr[4])
hist(x, col = 'blue', add = TRUE)
abline(v=c(-1),lty=1,lwd=3,col=black)
do.call(clip, as.list(usr))  # reset to plot region





--
View this message in context: 
http://r.789695.n4.nabble.com/Histogram-plot-help-tp4651958.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] Histogram plot help

2012-12-03 Thread Rui Barradas

Hello,

I can't say I understand your graph but as for the abline not showing 
up, it's outside the clipped region so it shouldn't. If you want it to 
show up, in the previous line, and after the hist() call, include


clip(2, -2, usr[3], usr[4])

As for the decimals, those are normal, have you seen the data you're 
ploting? To have whole numbers use the arguments ylim and yaxt = n in 
the first call to hist and axis(2, ...) afterward. Something like


hist(x, xlim=c(-4,4),ylab=Prevalence,prob=T,lwd=3,las=1, ylim = c(0, 
3), yaxt=n)

axis(2, at = 0:3)


Oh, and you forgot prob = TRUE in the other calls to hist().

Hope this helps,

Rui Barradas

Em 03-12-2012 22:21, YAddo escreveu:

Dear All:

I plotted a histogram with Abline, clipping with color codes but i run into
some problems.   The abline' does not show up at all,  and when i request
the 'prob=True' (to obtain the freqs), my clipped region colors the section
of the graph instead of the plot only.

Is there any way i can get the y-axis figures  to be in whole numbers rather
than decimals?

Many thanks for your help.
YA

Here are the working codes i am tweaking.

Everything worked fine before i trying adding stuffs (prob=T, etc).


x - rnorm(1000)
hist(x, xlim=c(-4,4),ylab=Prevalence,prob=T,lwd=3,las=1)
lines(density(x),col=black,lwd=2)
usr - par(usr)
clip(usr[1], -2, usr[3], usr[4])
hist(x, col = 'red', add = TRUE)
clip(2, usr[2], usr[3], usr[4])
hist(x, col = 'blue', add = TRUE)
abline(v=c(-1),lty=1,lwd=3,col=black)
do.call(clip, as.list(usr))  # reset to plot region





--
View this message in context: 
http://r.789695.n4.nabble.com/Histogram-plot-help-tp4651958.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] Histogram plot help

2012-12-03 Thread David L Carlson
Does it work the way you want if you add prob=TRUE to the second and third
hist() commands and run do.call() before abline()?

--
David L Carlson
Associate Professor of Anthropology
Texas AM University
College Station, TX 77843-4352

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of YAddo
 Sent: Monday, December 03, 2012 4:22 PM
 To: r-help@r-project.org
 Subject: [R] Histogram plot help
 
 Dear All:
 
 I plotted a histogram with Abline, clipping with color codes but i run
 into
 some problems.   The abline' does not show up at all,  and when i
 request
 the 'prob=True' (to obtain the freqs), my clipped region colors the
 section
 of the graph instead of the plot only.
 
 Is there any way i can get the y-axis figures  to be in whole numbers
 rather
 than decimals?
 
 Many thanks for your help.
 YA
 
 Here are the working codes i am tweaking.
 
 Everything worked fine before i trying adding stuffs (prob=T, etc).
 
 
 x - rnorm(1000)
 hist(x, xlim=c(-4,4),ylab=Prevalence,prob=T,lwd=3,las=1)
 lines(density(x),col=black,lwd=2)
 usr - par(usr)
 clip(usr[1], -2, usr[3], usr[4])
 hist(x, col = 'red', add = TRUE)
 clip(2, usr[2], usr[3], usr[4])
 hist(x, col = 'blue', add = TRUE)
 abline(v=c(-1),lty=1,lwd=3,col=black)
 do.call(clip, as.list(usr))  # reset to plot region
 
 
 
 
 
 --
 View this message in context: http://r.789695.n4.nabble.com/Histogram-
 plot-help-tp4651958.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] histogram help

2012-11-22 Thread Jim Lemon

On 11/22/2012 05:15 AM, Rosario Scandurra wrote:

Hi,

I want to generate an histogram and plot on the y axis the percentage of a
categorical variable and on the x axis a nominal variable. I want to move
the origin to have 2 categories below 0. Hope somebody could help me.
Thanks.


Hi Rosario,
If you already have your percentages, the barplot function will display 
them like most people expect an histogram to look by setting space=0. 
See the names.arg argument to have the names of your nominal variables 
on the x axis. I'm not sure exactly what you mean by wanting 2 
categories below 0. If these are negative percentages, the barplot 
function will automatically handle them.


Jim

__
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] histogram help

2012-11-21 Thread Rosario Scandurra
Hi,

I want to generate an histogram and plot on the y axis the percentage of a
categorical variable and on the x axis a nominal variable. I want to move
the origin to have 2 categories below 0. Hope somebody could help me.
Thanks.

Best,
-- 
Rosario Ivano Scandurra

[[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] histogram help

2012-11-21 Thread John Kane
i think we need some sample data.  

I would not have thought that you could calculate the percentage of a 
categorical data so perhaps a simple example of what you are doing would help.

John Kane
Kingston ON Canada


 -Original Message-
 From: rosario.scandu...@gmail.com
 Sent: Wed, 21 Nov 2012 19:15:53 +0100
 To: r-help@r-project.org
 Subject: [R] histogram help
 
 Hi,
 
 I want to generate an histogram and plot on the y axis the percentage of
 a
 categorical variable and on the x axis a nominal variable. I want to move
 the origin to have 2 categories below 0. Hope somebody could help me.
 Thanks.
 
 Best,
 --
 Rosario Ivano Scandurra
 
   [[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.


FREE ONLINE PHOTOSHARING - Share your photos online with your friends and 
family!
Visit http://www.inbox.com/photosharing to find out more!

__
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] histogram corelation plots

2012-10-10 Thread sagarnikam123
i want to show histogram in innovative way (good if interactive) in html
report..is threre any tutorials/hint
also there is any package to show correalation plot



--
View this message in context: 
http://r.789695.n4.nabble.com/histogram-corelation-plots-tp4645726.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] histogram corelation plots

2012-10-10 Thread R. Michael Weylandt
On Wed, Oct 10, 2012 at 4:47 PM, sagarnikam123 sagarnikam...@gmail.com wrote:
 i want to show histogram in innovative way (good if interactive) in html
 report..is threre any tutorials/hint
 also there is any package to show correalation plot

The histogram is well defined, so I'm not really sure how much
innovation you should do there. However, check

Acinonyx::ihist()

from Rforge (not R-forge) for interactive.

library(corrgram)

for correlation plots.

Cheers,
Michael

__
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] histogram corelation plots

2012-10-10 Thread David L Carlson
As for interactive plots, there is also aplpack (sliders for changing the
width of histograms, and density plots; iPlots; and iWebPlots.

--
David L Carlson
Associate Professor of Anthropology
Texas AM University
College Station, TX 77843-4352



 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of R. Michael Weylandt
 Sent: Wednesday, October 10, 2012 3:04 PM
 To: sagarnikam123
 Cc: r-help@r-project.org
 Subject: Re: [R] histogram  corelation plots
 
 On Wed, Oct 10, 2012 at 4:47 PM, sagarnikam123
 sagarnikam...@gmail.com wrote:
  i want to show histogram in innovative way (good if interactive) in
 html
  report..is threre any tutorials/hint
  also there is any package to show correalation plot
 
 The histogram is well defined, so I'm not really sure how much
 innovation you should do there. However, check
 
 Acinonyx::ihist()
 
 from Rforge (not R-forge) for interactive.
 
 library(corrgram)
 
 for correlation plots.
 
 Cheers,
 Michael
 
 __
 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.


[R] histogram plot spacing problem

2012-09-19 Thread firespot

Hi,

So I plot a histogram using the built-in hist function:

hist(rnorm(100), ...).

Now the y-axis starts at its lower end at 0 (very sensible, of course) 
and that's where the baseline for the rectangles of the histogram is 
drawn, but the x-axis itself is offset a bit to the lower. I.e. there is 
some space between x-axis and null-point of y-axis / histogram lower end.
What do I need to do to get rid of that space, so that x- and y-axis 
will intersect at y=0 ? Ideally the solution should be device- and 
screen-size independent.


thanks!

__
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] histogram plot spacing problem

2012-09-19 Thread Rui Barradas

Hello,

Try the following.


x - rnorm(100)
hist(x, xaxt = n)
axis(1, at = pretty(x), pos = 0)

Hope this helps,

Rui Barradas
Em 19-09-2012 18:51, firespot escreveu:

Hi,

So I plot a histogram using the built-in hist function:

hist(rnorm(100), ...).

Now the y-axis starts at its lower end at 0 (very sensible, of course) 
and that's where the baseline for the rectangles of the histogram is 
drawn, but the x-axis itself is offset a bit to the lower. I.e. there 
is some space between x-axis and null-point of y-axis / histogram 
lower end.
What do I need to do to get rid of that space, so that x- and y-axis 
will intersect at y=0 ? Ideally the solution should be device- and 
screen-size independent.


thanks!

__
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] Histogram to KDE

2012-09-06 Thread Tim Hesterberg
To bootstrap from a histogram, use
  sample(bins, replace = TRUE, prob = counts)

Note that a kernel density estimate is biased, so some bootstrap
confidence intervals have poor coverage properties.
Furthermore, if the kernel bandwidth is data-driven then the estimate
is not functional, so some bootstrap and jackknife methods won't work right.

Tim Hesterberg
http://www.timhesterberg.net
New:  Mathematical Statistics with Resampling and R, Chihara  Hesterberg

On Fri, Aug 31, 2012 at 12:15 PM, David L Carlson dcarl...@tamu.edu wrote:

 Using a data.frame x with columns bins and counts:

 x - structure(list(bins = c(3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5,
 11.5, 12.5, 13.5, 14.5, 15.5), counts = c(1, 1, 2, 3, 6, 18,
 19, 23, 8, 10, 6, 2, 1)), .Names = c(bins, counts), row.names =
 4:16,
 class = data.frame)

 This will give you a plot of the kde estimate:


Thanks.


 xkde - density(rep(bins, counts), bw=SJ)
 plot(xkde)

 As for the standard error or the confidence interval, you would probably
 need to use bootstrapping.



 On a similar note - is there a way in R to directly resample /
cross-validate from a histogram of a data-set without recreating the
original data-set ?


   -Original Message-
 
  Hello,
  I wanted to know if there was way to convert a histogram of a data-set
  to a
  kernel density estimate directly in R ?
 
  Specifically, I have a histogram [bins, counts] of samples {X1 ...
  XN} of a quantized variable X where there is one bin for each level of
  X,
  and I'ld like to directly get a kde estimate of the pdf of X from the
  histogram. Therefore, there is no additional quantization of X in the
  histogram. Most KDE methods in R seem to require the original sample
  set   - and I would like to avoid re-creating the samples from the
  histogram. Is there some quick way of doing this using one of the
  standard
  kde methods in R ?
 
  Also, a general statistical question - is there some measure of the
  standard error or confidence interval or similar of a KDE of a data-set
  ?
 
  Thanks,
  -fj
 


   [[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] Histogram to KDE

2012-09-05 Thread firdaus.janoos
On Fri, Aug 31, 2012 at 12:15 PM, David L Carlson dcarl...@tamu.edu wrote:

 Using a data.frame x with columns bins and counts:

 x - structure(list(bins = c(3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5,
 11.5, 12.5, 13.5, 14.5, 15.5), counts = c(1, 1, 2, 3, 6, 18,
 19, 23, 8, 10, 6, 2, 1)), .Names = c(bins, counts), row.names =
 4:16,
 class = data.frame)

 This will give you a plot of the kde estimate:


Thanks.


 xkde - density(rep(bins, counts), bw=SJ)
 plot(xkde)

 As for the standard error or the confidence interval, you would probably
 need to use bootstrapping.



 On a similar note - is there a way in R to directly resample /
cross-validate from a histogram of a data-set without recreating the
original data-set ?


   -Original Message-
 
  Hello,
  I wanted to know if there was way to convert a histogram of a data-set
  to a
  kernel density estimate directly in R ?
 
  Specifically, I have a histogram [bins, counts] of samples {X1 ...
  XN} of a quantized variable X where there is one bin for each level of
  X,
  and I'ld like to directly get a kde estimate of the pdf of X from the
  histogram. Therefore, there is no additional quantization of X in the
  histogram. Most KDE methods in R seem to require the original sample
  set   - and I would like to avoid re-creating the samples from the
  histogram. Is there some quick way of doing this using one of the
  standard
  kde methods in R ?
 
  Also, a general statistical question - is there some measure of the
  standard error or confidence interval or similar of a KDE of a data-set
  ?
 
  Thanks,
  -fj
 


[[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] Histogram to KDE

2012-08-31 Thread firdaus.janoos
Hello,
I wanted to know if there was way to convert a histogram of a data-set to a
kernel density estimate directly in R ?

Specifically, I have a histogram [bins, counts] of samples {X1 ...
XN} of a quantized variable X where there is one bin for each level of X,
and I'ld like to directly get a kde estimate of the pdf of X from the
histogram. Therefore, there is no additional quantization of X in the
histogram. Most KDE methods in R seem to require the original sample
set   - and I would like to avoid re-creating the samples from the
histogram. Is there some quick way of doing this using one of the standard
kde methods in R ?

Also, a general statistical question - is there some measure of the
standard error or confidence interval or similar of a KDE of a data-set ?

Thanks,
-fj

[[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] Histogram to KDE

2012-08-31 Thread David L Carlson
Using a data.frame x with columns bins and counts:

x - structure(list(bins = c(3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 
11.5, 12.5, 13.5, 14.5, 15.5), counts = c(1, 1, 2, 3, 6, 18, 
19, 23, 8, 10, 6, 2, 1)), .Names = c(bins, counts), row.names =
4:16,
class = data.frame)

This will give you a plot of the kde estimate:

xkde - density(rep(bins, counts), bw=SJ)
plot(xkde)

As for the standard error or the confidence interval, you would probably
need to use bootstrapping. 

--
David L Carlson
Associate Professor of Anthropology
Texas AM University
College Station, TX 77843-4352

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of firdaus.janoos
 Sent: Friday, August 31, 2012 9:52 AM
 To: r-help@r-project.org
 Subject: [R] Histogram to KDE
 
 Hello,
 I wanted to know if there was way to convert a histogram of a data-set
 to a
 kernel density estimate directly in R ?
 
 Specifically, I have a histogram [bins, counts] of samples {X1 ...
 XN} of a quantized variable X where there is one bin for each level of
 X,
 and I'ld like to directly get a kde estimate of the pdf of X from the
 histogram. Therefore, there is no additional quantization of X in the
 histogram. Most KDE methods in R seem to require the original sample
 set   - and I would like to avoid re-creating the samples from the
 histogram. Is there some quick way of doing this using one of the
 standard
 kde methods in R ?
 
 Also, a general statistical question - is there some measure of the
 standard error or confidence interval or similar of a KDE of a data-set
 ?
 
 Thanks,
 -fj
 
   [[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-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] Histogram

2012-07-30 Thread Jim Silverton
I have the following codes:
Now, suppose I have x = runif(1000,0,1, rep(1, 250), rep(0, 100) and I want
to create a 'bin' for the 0's and the 1's and put the rest of the values in
say about 20 bins. How can this be done?

Jim





On Thu, Jul 5, 2012 at 4:08 PM, Sarah Goslee sarah.gos...@gmail.com wrote:

 Which gives Jim two ways to arrive at exactly the same result, just
 different means of specifying the probs for quantile().

 Sarah

 On Thu, Jul 5, 2012 at 4:01 PM, Rui Barradas ruipbarra...@sapo.pt wrote:
  Hello,
 
  With the confusion between bin size and width the OP started, I'll
 repost my
  answer with a final line. Sorry for the repetition.
 
 
  h - hist(x, breaks=quantile(x, probs=seq(0, 1, by=1/20)))
  h$counts
  [1] 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50
 
 
  Hope this helps,
 
  Rui Barradas
 
  Em 05-07-2012 20:47, Sarah Goslee escreveu:
 
  There's no reason you can't do that with normally-distributed data,
  though I'm not sure why you'd want to. My point was rather that you
  can't specify the bin width and size both. If you let the bin size
  vary, this will work:
 
  set.seed(1234)
  mydata - rnorm(1000, mean = 2, sd = 4)
  mydata.hist - hist(mydata, breaks=quantile(mydata, probs=seq(0, 1,
  length.out = length(mydata)/50 + 1)))
  mydata.hist$counts
 
 
  Sarah
 
  On Thu, Jul 5, 2012 at 3:37 PM, Jim Silverton jim.silver...@gmail.com
  wrote:
 
  Thanks Sarah!!
  Ok so if I have say x = runif(1000,0,1) say instead if the normal and I
  want
  a histogram with bins that have an equal number of observations. For
  example
  if I want each bin to have 50 observations, how do I do this?
 
 
 
  On Thu, Jul 5, 2012 at 3:34 PM, Sarah Goslee sarah.gos...@gmail.com
  wrote:
 
 
  Hi Jim,
 
  You can't specify both number of bins and bin size. You can specify
  breaks: either the number of bins or the location of breakpoints. A
  histogram with 20 bins of 50 observations each must by definition come
  from a uniform distribution.
 
  What are you trying to accomplish?
 
  Sarah
 
  On Thu, Jul 5, 2012 at 3:29 PM, Jim Silverton 
 jim.silver...@gmail.com
  wrote:
 
  I have a column of 1000 datapoints from the normal distribution with
  mean 2
  and variance 4. How can I get a histogram of these observations with
 20
  bins with each bin having 50 observations?
 
  --
  Thanks,
  Jim.
 
 
 
 




-- 
Thanks,
Jim.

[[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] Histogram

2012-07-30 Thread David Winsemius


On Jul 30, 2012, at 9:29 AM, Jim Silverton wrote:


I have the following codes:
Now, suppose I have x = runif(1000,0,1, rep(1, 250), rep(0, 100) and  
I want
to create a 'bin' for the 0's and the 1's and put the rest of the  
values in

say about 20 bins. How can this be done?


?cut

--
David.


Jim





On Thu, Jul 5, 2012 at 4:08 PM, Sarah Goslee  
sarah.gos...@gmail.com wrote:



Which gives Jim two ways to arrive at exactly the same result, just
different means of specifying the probs for quantile().

Sarah

On Thu, Jul 5, 2012 at 4:01 PM, Rui Barradas ruipbarra...@sapo.pt  
wrote:

Hello,

With the confusion between bin size and width the OP started, I'll

repost my

answer with a final line. Sorry for the repetition.


h - hist(x, breaks=quantile(x, probs=seq(0, 1, by=1/20)))
h$counts
[1] 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50


Hope this helps,

Rui Barradas

Em 05-07-2012 20:47, Sarah Goslee escreveu:


There's no reason you can't do that with normally-distributed data,
though I'm not sure why you'd want to. My point was rather that you
can't specify the bin width and size both. If you let the bin size
vary, this will work:

set.seed(1234)
mydata - rnorm(1000, mean = 2, sd = 4)
mydata.hist - hist(mydata, breaks=quantile(mydata, probs=seq(0, 1,
length.out = length(mydata)/50 + 1)))
mydata.hist$counts


Sarah

On Thu, Jul 5, 2012 at 3:37 PM, Jim Silverton jim.silver...@gmail.com 


wrote:


Thanks Sarah!!
Ok so if I have say x = runif(1000,0,1) say instead if the  
normal and I

want
a histogram with bins that have an equal number of observations.  
For

example
if I want each bin to have 50 observations, how do I do this?



On Thu, Jul 5, 2012 at 3:34 PM, Sarah Goslee sarah.gos...@gmail.com 


wrote:



Hi Jim,

You can't specify both number of bins and bin size. You can  
specify
breaks: either the number of bins or the location of  
breakpoints. A
histogram with 20 bins of 50 observations each must by  
definition come

from a uniform distribution.

What are you trying to accomplish?

Sarah

On Thu, Jul 5, 2012 at 3:29 PM, Jim Silverton 

jim.silver...@gmail.com

wrote:


I have a column of 1000 datapoints from the normal  
distribution with

mean 2
and variance 4. How can I get a histogram of these  
observations with

20

bins with each bin having 50 observations?

--
Thanks,
Jim.













--
Thanks,
Jim.

[[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.


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.


Re: [R] histogram of time-stamp data

2012-07-17 Thread e-letter
On 16/07/2012, Rui Barradas ruipbarra...@sapo.pt wrote:
 Hello,

 Em 16-07-2012 22:45, e-letter escreveu:
 On 16/07/2012, r-help-requ...@r-project.org
   r-help-requ...@r-project.org wrote:
--
   
Message: 77
Date: Mon, 16 Jul 2012 10:48:39 +0100
From: Rui Barradas ruipbarra...@sapo.pt
To: e-letter inp...@gmail.com
Cc: r-help@r-project.org
Subject: Re: [R] histogram of time-stamp data
Message-ID: 5003e377.3000...@sapo.pt
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
   
   
timestamps - as.POSIXct(Sys.Date()) + sample(24*60*60, 1e3, TRUE)
   

   Why is it necessary to apply the sample to the current date? Looking
   at the dataframe, I noticed that values have been changed:

 No! That instruction is just to create a data example with more
 date/time values, in this case with a total of 1e3 different values.
 What's important is the way to plot the histogram, namely, the cut()
 with two example time periods, and that hist() needs numbers, not cut's
 levels.


With the original data provided, R reports an error, that 'x' must be numeric'.

__
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] histogram of time-stamp data

2012-07-17 Thread Rui Barradas

Hello,

That's not the error I've had. You must be aware that read.table creates 
a data.frame and therefore the object 'timestamps' is NOT holding time 
stamps, it's holding a vector, 'V1', of time stamps.



timestamps - read.table(text=
12:19:00
09:30:00
16:56:00
01:56:00
10:44:00
10:31:00
02:14:00
05:05:00
12:52:00
21:50:00
, stringsAsFactors=FALSE)
str(timestamps)

timestamps - as.POSIXct(timestamps$V1, format=%H:%M:%S)  # here

h1 - cut(timestamps, breaks=hour)
h2 - cut(timestamps, breaks=15 mins)

op - par(mfrow=c(1, 2))
hist(as.integer(h1))
hist(as.integer(h2))
par(op)


And the rest works.

Rui Barradas

Em 17-07-2012 07:11, e-letter escreveu:

On 16/07/2012, Rui Barradas ruipbarra...@sapo.pt wrote:

Hello,

Em 16-07-2012 22:45, e-letter escreveu:

On 16/07/2012, r-help-requ...@r-project.org
   r-help-requ...@r-project.org wrote:
--
   
Message: 77
Date: Mon, 16 Jul 2012 10:48:39 +0100
From: Rui Barradas ruipbarra...@sapo.pt
To: e-letter inp...@gmail.com
Cc: r-help@r-project.org
Subject: Re: [R] histogram of time-stamp data
Message-ID: 5003e377.3000...@sapo.pt
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
   
   
timestamps - as.POSIXct(Sys.Date()) + sample(24*60*60, 1e3, TRUE)
   

   Why is it necessary to apply the sample to the current date? Looking
   at the dataframe, I noticed that values have been changed:


No! That instruction is just to create a data example with more
date/time values, in this case with a total of 1e3 different values.
What's important is the way to plot the histogram, namely, the cut()
with two example time periods, and that hist() needs numbers, not cut's
levels.



With the original data provided, R reports an error, that 'x' must be numeric'.



__
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] histogram of time-stamp data

2012-07-17 Thread e-letter
On 17/07/2012, Rui Barradas ruipbarra...@sapo.pt wrote:
 Hello,

 That's not the error I've had. You must be aware that read.table creates
 a data.frame and therefore the object 'timestamps' is NOT holding time
 stamps, it's holding a vector, 'V1', of time stamps.


Was not aware of the significance of the data frame of vector values.

 ..., stringsAsFactors=FALSE)


Can confirm the success of adding this parameter to the command 'read.table'

 timestamps - as.POSIXct(timestamps$V1, format=%H:%M:%S)  # here

 h1 - cut(timestamps, breaks=hour)

 And the rest works.


Confirmed, thanks.

__
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] histogram of time-stamp data

2012-07-16 Thread e-letter
Readers,

A data set consists of time-stamp values:

00:00:00
23:11:00
06:22:00

The data set was imported:

timestamps-read.table(path/to/timestampsvalues)
hist(timestamps)

...error... x must be numeric

Then tried:

plot(timestamps).

How to adjust the graph to create a histogram where the intervals
ranges can be specified, e.g. intervals of 60 minutes?

Thanks in advance.

__
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] histogram of time-stamp data

2012-07-16 Thread Jessica Streicher
pDates-as.POSIXct(times,format=%H:%M:%S)
 hist(pDates,hours)

On 16.07.2012, at 10:47, e-letter wrote:

 Readers,
 
 A data set consists of time-stamp values:
 
 00:00:00
 23:11:00
 06:22:00
 
 The data set was imported:
 
 timestamps-read.table(path/to/timestampsvalues)
 hist(timestamps)
 
 ...error... x must be numeric
 
 Then tried:
 
 plot(timestamps).
 
 How to adjust the graph to create a histogram where the intervals
 ranges can be specified, e.g. intervals of 60 minutes?
 
 Thanks in advance.
 
 __
 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] histogram of time-stamp data

2012-07-16 Thread Rui Barradas

Hello,

Try the following.


timestamps - as.POSIXct(Sys.Date()) + sample(24*60*60, 1e3, TRUE)

h1 - cut(timestamps, breaks=hour)
h2 - cut(timestamps, breaks=15 mins)

op - par(mfrow=c(1, 2))
hist(as.integer(h1))
hist(as.integer(h2))
par(op)


Hope this helps,

Rui Barradas

Em 16-07-2012 09:47, e-letter escreveu:

Readers,

A data set consists of time-stamp values:

00:00:00
23:11:00
06:22:00

The data set was imported:

timestamps-read.table(path/to/timestampsvalues)
hist(timestamps)

...error... x must be numeric

Then tried:

plot(timestamps).

How to adjust the graph to create a histogram where the intervals
ranges can be specified, e.g. intervals of 60 minutes?

Thanks in advance.

__
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] histogram of time-stamp data

2012-07-16 Thread e-letter
On 16/07/2012, r-help-requ...@r-project.org
 r-help-requ...@r-project.org wrote:
  --
 
  Message: 77
  Date: Mon, 16 Jul 2012 10:48:39 +0100
  From: Rui Barradas ruipbarra...@sapo.pt
  To: e-letter inp...@gmail.com
  Cc: r-help@r-project.org
  Subject: Re: [R] histogram of time-stamp data
  Message-ID: 5003e377.3000...@sapo.pt
  Content-Type: text/plain; charset=ISO-8859-1; format=flowed
 
 
  timestamps - as.POSIXct(Sys.Date()) + sample(24*60*60, 1e3, TRUE)
 

 Why is it necessary to apply the sample to the current date? Looking
 at the dataframe, I noticed that values have been changed:

 file 'test.txt':
 12:19:00
 09:30:00
 16:56:00
 01:56:00
 10:44:00
 10:31:00
 02:14:00
 05:05:00
 12:52:00
 21:50:00

 R command terminal input:
  timestamps-read.table(test.txt)
  timestamps
  V1
 1  12:19:00
 2  09:30:00
 3  16:56:00
 4  01:56:00
 5  10:44:00
 6  10:31:00
 7  02:14:00
 8  05:05:00
 9  12:52:00
 10 21:50:00
  timestamps - as.POSIXct(Sys.Date()) + sample(24*60*60, 1e3, TRUE)
  write.csv(timestamps,file=test1.txt)

 test1.txt:
 ,x
 1,2012-07-16 04:52:48
 2,2012-07-16 21:21:28
 3,2012-07-16 18:58:27
 4,2012-07-16 22:17:25
 5,2012-07-16 11:13:52
 6,2012-07-16 03:17:35
 7,2012-07-16 02:14:17
 8,2012-07-16 14:18:27
 9,2012-07-16 14:39:16

 Why is this happening?

__
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] histogram of time-stamp data

2012-07-16 Thread Rui Barradas

Hello,

Em 16-07-2012 22:45, e-letter escreveu:

On 16/07/2012, r-help-requ...@r-project.org
  r-help-requ...@r-project.org wrote:
   --
  
   Message: 77
   Date: Mon, 16 Jul 2012 10:48:39 +0100
   From: Rui Barradas ruipbarra...@sapo.pt
   To: e-letter inp...@gmail.com
   Cc: r-help@r-project.org
   Subject: Re: [R] histogram of time-stamp data
   Message-ID: 5003e377.3000...@sapo.pt
   Content-Type: text/plain; charset=ISO-8859-1; format=flowed
  
  
   timestamps - as.POSIXct(Sys.Date()) + sample(24*60*60, 1e3, TRUE)
  

  Why is it necessary to apply the sample to the current date? Looking
  at the dataframe, I noticed that values have been changed:


No! That instruction is just to create a data example with more 
date/time values, in this case with a total of 1e3 different values. 
What's important is the way to plot the histogram, namely, the cut() 
with two example time periods, and that hist() needs numbers, not cut's 
levels.


Rui Barradas



  file 'test.txt':
  12:19:00
  09:30:00
  16:56:00
  01:56:00
  10:44:00
  10:31:00
  02:14:00
  05:05:00
  12:52:00
  21:50:00

  R command terminal input:
   timestamps-read.table(test.txt)
   timestamps
   V1
  1  12:19:00
  2  09:30:00
  3  16:56:00
  4  01:56:00
  5  10:44:00
  6  10:31:00
  7  02:14:00
  8  05:05:00
  9  12:52:00
  10 21:50:00
   timestamps - as.POSIXct(Sys.Date()) + sample(24*60*60, 1e3, TRUE)
   write.csv(timestamps,file=test1.txt)

  test1.txt:
  ,x
  1,2012-07-16 04:52:48
  2,2012-07-16 21:21:28
  3,2012-07-16 18:58:27
  4,2012-07-16 22:17:25
  5,2012-07-16 11:13:52
  6,2012-07-16 03:17:35
  7,2012-07-16 02:14:17
  8,2012-07-16 14:18:27
  9,2012-07-16 14:39:16

  Why is this happening?



__
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] Histogram

2012-07-05 Thread Jim Silverton
I have a column of 1000 datapoints from the normal distribution with mean 2
and variance 4. How can I get a histogram of these observations with 20
bins with each bin having 50 observations?

-- 
Thanks,
Jim.

[[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] Histogram

2012-07-05 Thread Sarah Goslee
Hi Jim,

You can't specify both number of bins and bin size. You can specify
breaks: either the number of bins or the location of breakpoints. A
histogram with 20 bins of 50 observations each must by definition come
from a uniform distribution.

What are you trying to accomplish?

Sarah

On Thu, Jul 5, 2012 at 3:29 PM, Jim Silverton jim.silver...@gmail.com wrote:
 I have a column of 1000 datapoints from the normal distribution with mean 2
 and variance 4. How can I get a histogram of these observations with 20
 bins with each bin having 50 observations?

 --
 Thanks,
 Jim.


-- 
Sarah Goslee
http://www.functionaldiversity.org

__
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] Histogram

2012-07-05 Thread Rui Barradas

Hello,

Try the following.

x - rnorm(1000, mean=2, sd=2)
p - seq(0, 1, by=1/20)
quant - quantile(x, probs=p)
hist(x, breaks=quant)


The method is absolutely general, that's why I've separated the several 
steps, to make it clear.


Hope this helps,

Rui Barradas

Em 05-07-2012 20:29, Jim Silverton escreveu:

I have a column of 1000 datapoints from the normal distribution with mean 2
and variance 4. How can I get a histogram of these observations with 20
bins with each bin having 50 observations?



__
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] Histogram

2012-07-05 Thread Sarah Goslee
There's no reason you can't do that with normally-distributed data,
though I'm not sure why you'd want to. My point was rather that you
can't specify the bin width and size both. If you let the bin size
vary, this will work:

set.seed(1234)
mydata - rnorm(1000, mean = 2, sd = 4)
mydata.hist - hist(mydata, breaks=quantile(mydata, probs=seq(0, 1,
length.out = length(mydata)/50 + 1)))
mydata.hist$counts


Sarah

On Thu, Jul 5, 2012 at 3:37 PM, Jim Silverton jim.silver...@gmail.com wrote:
 Thanks Sarah!!
 Ok so if I have say x = runif(1000,0,1) say instead if the normal and I want
 a histogram with bins that have an equal number of observations. For example
 if I want each bin to have 50 observations, how do I do this?



 On Thu, Jul 5, 2012 at 3:34 PM, Sarah Goslee sarah.gos...@gmail.com wrote:

 Hi Jim,

 You can't specify both number of bins and bin size. You can specify
 breaks: either the number of bins or the location of breakpoints. A
 histogram with 20 bins of 50 observations each must by definition come
 from a uniform distribution.

 What are you trying to accomplish?

 Sarah

 On Thu, Jul 5, 2012 at 3:29 PM, Jim Silverton jim.silver...@gmail.com
 wrote:
  I have a column of 1000 datapoints from the normal distribution with
  mean 2
  and variance 4. How can I get a histogram of these observations with 20
  bins with each bin having 50 observations?
 
  --
  Thanks,
  Jim.


-- 
Sarah Goslee
http://www.functionaldiversity.org

__
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] Histogram

2012-07-05 Thread Duncan Murdoch

On 05/07/2012 3:34 PM, Sarah Goslee wrote:

Hi Jim,

You can't specify both number of bins and bin size. You can specify
breaks: either the number of bins or the location of breakpoints. A
histogram with 20 bins of 50 observations each must by definition come
from a uniform distribution.


Only if the bins are equal in size.  You could set the bins to 
quantiles, for the following ugly plot:


hist(x, breaks=quantile(x, seq(0, 1, by=0.05)))

Duncan Murdoch



What are you trying to accomplish?

Sarah

On Thu, Jul 5, 2012 at 3:29 PM, Jim Silverton jim.silver...@gmail.com wrote:
 I have a column of 1000 datapoints from the normal distribution with mean 2
 and variance 4. How can I get a histogram of these observations with 20
 bins with each bin having 50 observations?

 --
 Thanks,
 Jim.




__
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] Histogram

2012-07-05 Thread Rui Barradas

Hello,

With the confusion between bin size and width the OP started, I'll 
repost my answer with a final line. Sorry for the repetition.



h - hist(x, breaks=quantile(x, probs=seq(0, 1, by=1/20)))
h$counts
[1] 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50


Hope this helps,

Rui Barradas

Em 05-07-2012 20:47, Sarah Goslee escreveu:

There's no reason you can't do that with normally-distributed data,
though I'm not sure why you'd want to. My point was rather that you
can't specify the bin width and size both. If you let the bin size
vary, this will work:

set.seed(1234)
mydata - rnorm(1000, mean = 2, sd = 4)
mydata.hist - hist(mydata, breaks=quantile(mydata, probs=seq(0, 1,
length.out = length(mydata)/50 + 1)))
mydata.hist$counts


Sarah

On Thu, Jul 5, 2012 at 3:37 PM, Jim Silverton jim.silver...@gmail.com wrote:

Thanks Sarah!!
Ok so if I have say x = runif(1000,0,1) say instead if the normal and I want
a histogram with bins that have an equal number of observations. For example
if I want each bin to have 50 observations, how do I do this?



On Thu, Jul 5, 2012 at 3:34 PM, Sarah Goslee sarah.gos...@gmail.com wrote:


Hi Jim,

You can't specify both number of bins and bin size. You can specify
breaks: either the number of bins or the location of breakpoints. A
histogram with 20 bins of 50 observations each must by definition come
from a uniform distribution.

What are you trying to accomplish?

Sarah

On Thu, Jul 5, 2012 at 3:29 PM, Jim Silverton jim.silver...@gmail.com
wrote:

I have a column of 1000 datapoints from the normal distribution with
mean 2
and variance 4. How can I get a histogram of these observations with 20
bins with each bin having 50 observations?

--
Thanks,
Jim.






__
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] Histogram

2012-07-05 Thread Sarah Goslee
Which gives Jim two ways to arrive at exactly the same result, just
different means of specifying the probs for quantile().

Sarah

On Thu, Jul 5, 2012 at 4:01 PM, Rui Barradas ruipbarra...@sapo.pt wrote:
 Hello,

 With the confusion between bin size and width the OP started, I'll repost my
 answer with a final line. Sorry for the repetition.


 h - hist(x, breaks=quantile(x, probs=seq(0, 1, by=1/20)))
 h$counts
 [1] 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50


 Hope this helps,

 Rui Barradas

 Em 05-07-2012 20:47, Sarah Goslee escreveu:

 There's no reason you can't do that with normally-distributed data,
 though I'm not sure why you'd want to. My point was rather that you
 can't specify the bin width and size both. If you let the bin size
 vary, this will work:

 set.seed(1234)
 mydata - rnorm(1000, mean = 2, sd = 4)
 mydata.hist - hist(mydata, breaks=quantile(mydata, probs=seq(0, 1,
 length.out = length(mydata)/50 + 1)))
 mydata.hist$counts


 Sarah

 On Thu, Jul 5, 2012 at 3:37 PM, Jim Silverton jim.silver...@gmail.com
 wrote:

 Thanks Sarah!!
 Ok so if I have say x = runif(1000,0,1) say instead if the normal and I
 want
 a histogram with bins that have an equal number of observations. For
 example
 if I want each bin to have 50 observations, how do I do this?



 On Thu, Jul 5, 2012 at 3:34 PM, Sarah Goslee sarah.gos...@gmail.com
 wrote:


 Hi Jim,

 You can't specify both number of bins and bin size. You can specify
 breaks: either the number of bins or the location of breakpoints. A
 histogram with 20 bins of 50 observations each must by definition come
 from a uniform distribution.

 What are you trying to accomplish?

 Sarah

 On Thu, Jul 5, 2012 at 3:29 PM, Jim Silverton jim.silver...@gmail.com
 wrote:

 I have a column of 1000 datapoints from the normal distribution with
 mean 2
 and variance 4. How can I get a histogram of these observations with 20
 bins with each bin having 50 observations?

 --
 Thanks,
 Jim.





__
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] histogram fill lattice

2012-06-15 Thread Deepayan Sarkar
On Wed, Jun 13, 2012 at 8:10 PM, David Winsemius dwinsem...@comcast.net wrote:

 On Jun 13, 2012, at 9:55 AM, Powell, Jeff wrote:


 Dear all,

 I would like to change the fill pattern of a histogram using histogram()
 in the lattice package.  I know how to do so using hist(), but would prefer
 to stay within lattice.

 dt1 - rnorm(100,0,1)

 hist(dt1, density=3, angle=45)


 I get diagonal striping.



 library(lattice)
 histogram(dt1,
              xlab = Histogram of rnorm(0,1),
              type = count,
              breaks = 15,
              col = grey)


 I seem to remember that the diagonal hatched fills were disabled or not
 brought over to lattice from base S graphics because they were thought to be
 causing cognitive distortions[1,2].

The actual reason it was not originally implemented is simply that
grid did not support it.  Of course, the bad-ness of hatching may
have been the reason grid doesn't support it, and why no one has
bothered to change the status quo in so many years.

-Deepayan

 You already seem to be able to specify
 the color of the fill, and it's easy to get alternating colored fills with
 col = c(grey,red) ,  so it's not entirely clear what your unsatisfied
 goals are.




 --
 David Winsemius, MD
 West Hartford, CT

 1]
 http://markmail.org/message/pmrrpjynrcnrwhg5?q=list:org%2Er-project%2Er-help+lattice+hatching
 2]
 http://markmail.org/message/cj23tnsgsobs4mbu?q=list:org%2Er-project%2Er-help+lattice+hatching


 __
 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] histogram fill lattice

2012-06-15 Thread Powell, Jeff
Thank you for your response, I will try to be clearer.  I would like to fill my 
lattice histogram bars using a symbol rather than a color.  If that is not 
possible, then I will use hist() instead.

From trellis.par.get()
bar.fill only includes col, so perhaps I'm out of luck?

With regards,
Jeff

-Original Message-
From: David Winsemius [mailto:dwinsem...@comcast.net] 
Sent: woensdag 13 juni 2012 16:40
To: Powell, Jeff
Cc: R-help@r-project.org
Subject: Re: [R] histogram fill lattice


On Jun 13, 2012, at 9:55 AM, Powell, Jeff wrote:


 Dear all,

 I would like to change the fill pattern of a histogram using
 histogram() in the lattice package.  I know how to do so using hist(), 
 but would prefer to stay within lattice.

 dt1 - rnorm(100,0,1)

 hist(dt1, density=3, angle=45)


I get diagonal striping.


 library(lattice)
 histogram(dt1,
   xlab = Histogram of rnorm(0,1),
   type = count,
   breaks = 15,
   col = grey)

I seem to remember that the diagonal hatched fills were disabled or not brought 
over to lattice from base S graphics because they were thought to be causing 
cognitive distortions[1,2]. You already seem to be able to specify the color of 
the fill, and it's easy to get alternating colored fills with col = 
c(grey,red) ,  so it's not entirely clear what your unsatisfied goals are.

--
David Winsemius, MD
West Hartford, CT

1] 
http://markmail.org/message/pmrrpjynrcnrwhg5?q=list:org%2Er-project%2Er-help+lattice+hatching
2] 
http://markmail.org/message/cj23tnsgsobs4mbu?q=list:org%2Er-project%2Er-help+lattice+hatching

__
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] histogram fill lattice

2012-06-15 Thread David Winsemius


On Jun 15, 2012, at 5:40 AM, Powell, Jeff wrote:

Thank you for your response, I will try to be clearer.  I would like  
to fill my lattice histogram bars using a symbol rather than a  
color.  If that is not possible, then I will use hist() instead.


From trellis.par.get()
bar.fill only includes col, so perhaps I'm out of luck?


Why didn't you say so ... here ya' go.

?grid.pattern

--
David


With regards,
Jeff

-Original Message-
From: David Winsemius [mailto:dwinsem...@comcast.net]
Sent: woensdag 13 juni 2012 16:40
To: Powell, Jeff
Cc: R-help@r-project.org
Subject: Re: [R] histogram fill lattice


On Jun 13, 2012, at 9:55 AM, Powell, Jeff wrote:



Dear all,

I would like to change the fill pattern of a histogram using
histogram() in the lattice package.  I know how to do so using  
hist(),

but would prefer to stay within lattice.

dt1 - rnorm(100,0,1)

hist(dt1, density=3, angle=45)



I get diagonal striping.



library(lattice)
histogram(dt1,
 xlab = Histogram of rnorm(0,1),
 type = count,
 breaks = 15,
 col = grey)


I seem to remember that the diagonal hatched fills were disabled or  
not brought over to lattice from base S graphics because they were  
thought to be causing cognitive distortions[1,2]. You already seem  
to be able to specify the color of the fill, and it's easy to get  
alternating colored fills with col = c(grey,red) ,  so it's not  
entirely clear what your unsatisfied goals are.


--
David Winsemius, MD
West Hartford, CT

1] 
http://markmail.org/message/pmrrpjynrcnrwhg5?q=list:org%2Er-project%2Er-help+lattice+hatching
2] 
http://markmail.org/message/cj23tnsgsobs4mbu?q=list:org%2Er-project%2Er-help+lattice+hatching







David Winsemius, MD
West Hartford, CT

__
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] histogram fill lattice

2012-06-13 Thread Powell, Jeff

Dear all,

I would like to change the fill pattern of a histogram using histogram() in 
the lattice package.  I know how to do so using hist(), but would prefer to 
stay within lattice.

dt1 - rnorm(100,0,1)

hist(dt1, density=3, angle=45)


library(lattice)
histogram(dt1,
   xlab = Histogram of rnorm(0,1),
   type = count,
   breaks = 15,
   col = grey)


With regards,
J. Powell





[[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] histogram fill lattice

2012-06-13 Thread David Winsemius


On Jun 13, 2012, at 9:55 AM, Powell, Jeff wrote:



Dear all,

I would like to change the fill pattern of a histogram using  
histogram() in the lattice package.  I know how to do so using  
hist(), but would prefer to stay within lattice.


dt1 - rnorm(100,0,1)

hist(dt1, density=3, angle=45)



I get diagonal striping.



library(lattice)
histogram(dt1,
  xlab = Histogram of rnorm(0,1),
  type = count,
  breaks = 15,
  col = grey)


I seem to remember that the diagonal hatched fills were disabled or  
not brought over to lattice from base S graphics because they were  
thought to be causing cognitive distortions[1,2]. You already seem to  
be able to specify the color of the fill, and it's easy to get  
alternating colored fills with col = c(grey,red) ,  so it's not  
entirely clear what your unsatisfied goals are.


--
David Winsemius, MD
West Hartford, CT

1] 
http://markmail.org/message/pmrrpjynrcnrwhg5?q=list:org%2Er-project%2Er-help+lattice+hatching
2] 
http://markmail.org/message/cj23tnsgsobs4mbu?q=list:org%2Er-project%2Er-help+lattice+hatching

__
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] Histogram classwise

2012-04-05 Thread Greg Snow
You might want to look at the lattice or ggplot2 packages, both of
which can create a graph for each of the classes.

On Tue, Apr 3, 2012 at 6:20 AM, arunkumar akpbond...@gmail.com wrote:
 Hi
 I have a data class wise. I want to create a histogram class wise without
 using for loop as it takes a long time
 my data looks like this

 x       class
 27      1
 93      3
 65      5
 1       2
 69      5
 2       1
 92      4
 49      5
 55      4
 46      1
 51      3
 100     4




 -
 Thanks in Advance
        Arun
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Histogram-classwise-tp4528624p4528624.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.



-- 
Gregory (Greg) L. Snow Ph.D.
538...@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] Histogram classwise

2012-04-03 Thread arunkumar1111
Hi 
I have a data class wise. I want to create a histogram class wise without
using for loop as it takes a long time 
my data looks like this

x   class
27  1
93  3
65  5
1   2
69  5
2   1
92  4
49  5
55  4
46  1
51  3
100 4




-
Thanks in Advance
Arun
--
View this message in context: 
http://r.789695.n4.nabble.com/Histogram-classwise-tp4528624p4528624.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] Histogram classwise

2012-04-03 Thread Sarah Goslee
I'm not entirely sure what you mean, but maybe split() and lapply() would help?

Sarah

On Tue, Apr 3, 2012 at 8:20 AM, arunkumar akpbond...@gmail.com wrote:
 Hi
 I have a data class wise. I want to create a histogram class wise without
 using for loop as it takes a long time
 my data looks like this

 x       class
 27      1
 93      3
 65      5
 1       2
 69      5
 2       1
 92      4
 49      5
 55      4
 46      1
 51      3
 100     4




 -
 Thanks in Advance
        Arun
 --

-- 
Sarah Goslee
http://www.functionaldiversity.org

__
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] Histogram from a table in R

2012-04-03 Thread gina_alessa
Hi all,

I am new in R. I am trying to make an histogram but I can't figure it out.
I have .cvs table with a lot of data that look like this: I already have the
frequency of each interval (Counts).

Interval   Counts
00:19   0
10:19  3117
20:29 4500
30:39 2330...

I want to make the histogram with that. At the y axis I want to have the
Counts and at x axis I want to have the intervals.

Thanks in advanced!!!




--
View this message in context: 
http://r.789695.n4.nabble.com/Histogram-from-a-table-in-R-tp4530175p4530175.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.


  1   2   3   4   >