[R] Histogram

2008-07-23 Thread Angelo Scozzarella

Hi,

how can I treat data organised in classes and frequencies?

Ex.

class   frequency

20-23   9
23-25   7
26-28   5
29-31   5
32-34   3



Thanks

Angelo Scozzarella

__
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

2008-09-14 Thread Felipe
i calculated the density and wanna do something like this

separate in 0-19-29-39-49-59-69-79-99
and put in these spaces 8 densities .. 0.something
i have the frequency in % and divided already in 20 or 10 to get the density

i tried and tried..made breaks vector to separate but couldn't put the other
vector with the frequency density onit directly

anyone know how to do it??

tks

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

2008-05-08 Thread Roslina Zakaria
Dear R-expert,
For histogram function, can we get the table of bin and frequency like in 
excel, together with the histogram?
Therefore, we can check the number of data included.
Thank you so much for your attention and help.


  


[[elided Yahoo spam]]

__
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

2008-05-15 Thread Roslina Zakaria
Hi r-expert,
I would like to plot histogram using frequency not density.
But I got the following warning.
 obs.hist <- 
hist(jan_data2[,4],right=FALSE,breaks=c(0,5,10,15,20,100),freq=TRUE,
+ xlab="Rain amt (mm)",ylim=c(0,3000),
+ main="Frequency of observed, Jan (1901-1990), Pooraka")
Warning message:
In plot.histogram(r, freq = freq1, col = col, border = border, angle = angle,  :
  the AREAS in the plot are wrong -- rather use freq=FALSE

I don't really understand the warning message and hope anybody can help me.
Thanks in advance for your help.  





__
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

2008-06-13 Thread Paul Adams
Hello everyone,
I am trying to plot a histogram from the following code:
dat<-read.table(file="C:\\Documents and Settings\\Owner\\My 
Documents\\Yeast\\Yeast.txt",header=T,row.names=1)
file.show(file="C:\\Documents and Settings\\Owner\\My 
Documents\\Yeast\\Yeast.txt")
x<-dat[2,23:46]
y=mean(x,trim=0,na.rm=T)
colMeans(dat[2,23:46])
boxplot(dat[2,23:46])
hist(dat[2,23:46])
The box plot is fine but the histogram keeps giving me the error that x
must be numeric.I am not sure what is wrong here with the instructions
for the histogram plot.
Any help would be appreciated
Paul


  
[[alternative HTML version deleted]]

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


[R] Histogram

2009-07-03 Thread aledanda

Hallo,

How can I have the control of the width of each bin in the histogram?
I would like to plot my data modifying the number and the width of the bins.

Is there a good pdf or manual where i can learn to use the plot/hist in R
very well?
I find the help not always clear

Thanks a lot


Ale
-- 
View this message in context: 
http://www.nabble.com/Histogram-tp24325261p24325261.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

2008-07-23 Thread milton ruser
I don´t know what you means by "treat", but may be you want something like
my.df<-read.table(stdin(), head=T, sep=",")
class,frequency
20-23,9
23-25,7
26-28,5
29-31,5
32-34,3

rownames(my.df)<-my.df$class
barplot (my.df$frequency)
axis(1, 1:dim(my.df)[1], rownames(my.df))

Cheers,
miltinho astronauta
brazil



On 7/23/08, Angelo Scozzarella <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> how can I treat data organised in classes and frequencies?
>
> Ex.
>
> class   frequency
>
> 20-23   9
> 23-25   7
> 26-28   5
> 29-31   5
> 32-34   3
>
>
>
> Thanks
>
> Angelo Scozzarella
>
> __
> 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

2008-07-23 Thread Henrique Dallazuanna
Try this:

with(x, barplot(frequency, names.arg = class))

On Wed, Jul 23, 2008 at 3:29 PM, Angelo Scozzarella
<[EMAIL PROTECTED]> wrote:
> Hi,
>
> how can I treat data organised in classes and frequencies?
>
> Ex.
>
> class   frequency
>
> 20-23   9
> 23-25   7
> 26-28   5
> 29-31   5
> 32-34   3
>
>
>
> Thanks
>
> Angelo Scozzarella
>
> __
> 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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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

2008-07-23 Thread Mark Difford

Hi Angelo,

Look carefully at package vcd; and at log-linear models (+ glm(...,
family=poisson)). For overdispersion there are more advanced methods.

HTH, Mark.


Angelo Scozzarella wrote:
> 
> Hi,
> 
> how can I treat data organised in classes and frequencies?
> 
> Ex.
> 
> class frequency
> 
> 20-23 9
> 23-25 7
> 26-28 5
> 29-31 5
> 32-34 3
> 
> 
> 
> Thanks
> 
> Angelo Scozzarella
> 
> __
> 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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Histogram-tp18617432p18619628.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

2008-07-23 Thread milton ruser
Try see doBy package.

Below you have a code on brute force.

kind regards,

miltinho
brazil

===
number.of.records<-20
my.df<-data.frame(v1=sample(21:34,number.of.records, replace=T),
v2=runif(number.of.records), v3=runif(number.of.records))
my.df$v1<-as.numeric(as.character(my.df$v1))
my.df$v2<-as.numeric(as.character(my.df$v2))
my.df$v3<-as.numeric(as.character(my.df$v3))

my.df

## up to here we just created a data.set

my.df$v1.class<-cut(my.df$v1,breaks=c(20,23,26,29,34))

my.df

my.stats<-aggregate(my.df[,c("v2","v3")], by=list(my.df$v1.class), length)
colnames(my.stats)<-c("v1.classs", "freq_v1", "freq_v2")
my.stats

my.stats<-cbind(my.stats, aggregate(my.df[,c("v2","v3")],
by=list(my.df$v1.class), mean))
colnames(my.stats)<-c("v1.classs", "freq_v1", "freq_v2", "rm1", "mean_v1",
"mean_v2")
my.stats

my.stats<-cbind(my.stats, aggregate(my.df[,c("v2","v3")],
by=list(my.df$v1.class), median))
colnames(my.stats)<-c("v1.classs", "freq_v1", "freq_v2", "rm1", "mean_v1",
"mean_v2",
 "rm2", "median_v1", "median_v2")
my.stats









On 7/23/08, Angelo Scozzarella <[EMAIL PROTECTED]> wrote:
>
> Thanks, but I want to calculate index like mean, median .
>
>
> How can I do it?
>
>
> Angelo Scozzarella
>
>
>
>  Il giorno 23/lug/08, alle ore 20:46, milton ruser ha scritto:
>
>  I don´t know what you means by "treat", but may be you want something
> like
> my.df<-read.table(stdin(), head=T, sep=",")
> class,frequency
> 20-23,9
> 23-25,7
> 26-28,5
> 29-31,5
> 32-34,3
>
> rownames(my.df)<-my.df$class
> barplot (my.df$frequency)
> axis(1, 1:dim(my.df)[1], rownames(my.df))
>
> Cheers,
> miltinho astronauta
> brazil
>
>
>
> On 7/23/08, Angelo Scozzarella <[EMAIL PROTECTED]> wrote:
>>
>> Hi,
>>
>> how can I treat data organised in classes and frequencies?
>>
>> Ex.
>>
>> class   frequency
>>
>> 20-23   9
>> 23-25   7
>> 26-28   5
>> 29-31   5
>> 32-34   3
>>
>>
>>
>> Thanks
>>
>> Angelo Scozzarella
>>
>> __
>> 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

2008-07-23 Thread Vincent Goulet

Le mer. 23 juil. à 14:29, Angelo Scozzarella a écrit :


Hi,

how can I treat data organised in classes and frequencies?

Ex.

class   frequency

20-23   9
23-25   7
26-28   5
29-31   5
32-34   3


It depends what you mean by "treat", but package actuar has a function  
grouped.data() to create such objects. Then, there are methods to  
compute the mean or plot the histogram. See the "lossdist" package  
vignette for details.


HTH  Vincent

--
  Vincent Goulet, Associate Professor
  École d'actuariat
  Université Laval, Québec
  [EMAIL PROTECTED]   http://vgoulet.act.ulaval.ca


Thanks

Angelo Scozzarella


__
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 binning

2008-08-19 Thread Ben Cox
I am trying to produce frequencies in defined intervals however I can't seem
to figure out how to get R to bin my data the way I want it to.

 

I have several thousand lengths of fish that I want to be binned as follows:


 

Ex.

 

Length  Bin

 

209 200

219 210

431 430

727 720

 

That is, bins with any length equal to or greater than the lower cutoff, but
smaller than the next higher cutoff should be included.  I have tried using
the right=FALSE and include.lowest in the hist function but it still puts
lengths that is greater than the cutoff into the next bin.

All software seems to bin right, but fish nerds do it a little different.

 

 

 

Thanks!  

Ben Cox

Graduate Research Assistant (M.S.)

Montana Cooperative Fishery Research Unit

Montana State University 

PO Box 173460

Bozeman, MT 59717

(406)994-6643 

 


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

2008-09-15 Thread Jim Lemon

Felipe wrote:

i calculated the density and wanna do something like this

separate in 0-19-29-39-49-59-69-79-99
and put in these spaces 8 densities .. 0.something
i have the frequency in % and divided already in 20 or 10 to get the density

i tried and tried..made breaks vector to separate but couldn't put the other
vector with the frequency density onit directly

anyone know how to do it??

Hi Felipe,
Try this:

library(plotrix)
testdat<-sample(1:100,1000,TRUE)
testfac<-cut(testdat,breaks=seq(0,100,by=10))
library(prettyR)
testdensity<-as.vector(freq(testfac,display.na=FALSE)[[1]])
barp(testdensity/1000,names.arg=names(testdensity),staxx=TRUE)

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

2008-09-14 Thread Adaikalavan Ramasamy
If I understand you correctly, you already pre-computed the frequencies 
and bin widths and want to display them as a histogram. If correct, then 
what you are asking for is analogous to what bxp() is to boxplot. I am 
not sure if such a function exists.


Instead you can think of the task as drawing a bunch of rectangles 
(perhaps using symbols?). Or you can hack the hist() code and try


   br<- c(0,20,30,40,50,60,70,80,100)
   dens  <- runif( length(br) - 1 )

   r <- structure(list(breaks = br, density = dens),
  class = "histogram")

   plot(r, main="Felipe's Histogram")

However, I do emphasize that this is a hack. If you have the original 
data that you used to calculate the densities, consider using the breaks 
argument with hist(). It is better to use tried and tested codes.


Regards, Adai



Felipe wrote:

i calculated the density and wanna do something like this

separate in 0-19-29-39-49-59-69-79-99
and put in these spaces 8 densities .. 0.something
i have the frequency in % and divided already in 20 or 10 to get the density

i tried and tried..made breaks vector to separate but couldn't put the other
vector with the frequency density onit directly

anyone know how to do it??

tks

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

2009-02-01 Thread Brendan Cusick
Hello.  I have what I'm sure is a very simple question.  Hopefully someone
can help.  I can't seem to find the maximum height of a histogram.  In
matlab it would be simple to say max(hist(x, 100)), but this doesn't seem to
work in R.  Any input would be greatly appreciated.

Brendan

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

2008-05-08 Thread Rolf Turner


On 9/05/2008, at 12:04 PM, Roslina Zakaria wrote:


Dear R-expert,
For histogram function, can we get the table of bin and frequency  
like in excel, together with the histogram?

Therefore, we can check the number of data included.
Thank you so much for your attention and help.


?hist

Look at the ``Value'' material.

cheers,

Rolf Turner

##
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

__
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

2008-05-08 Thread David Scott

On Thu, 8 May 2008, Roslina Zakaria wrote:


Dear R-expert,
For histogram function, can we get the table of bin and frequency like in 
excel, together with the histogram?
Therefore, we can check the number of data included.
Thank you so much for your attention and help.



Easy one: just use the argument plot=FALSE and hist will produce the 
counts etc for you


David Scott

_
David Scott Department of Statistics, Tamaki Campus
The University of Auckland, PB 92019
Auckland 1142,NEW ZEALAND
Phone: +64 9 373 7599 ext 86830 Fax: +64 9 373 7000
Email:  [EMAIL PROTECTED]

Graduate Officer, Department of Statistics
Director of Consulting, Department of Statistics

__
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

2008-05-08 Thread Ted Harding
On 09-May-08 00:12:46, David Scott wrote:
> On Thu, 8 May 2008, Roslina Zakaria wrote:
> 
>> Dear R-expert,
>> For histogram function, can we get the table of bin and
>> frequency like in excel, together with the histogram?
>> Therefore, we can check the number of data included.
>> Thank you so much for your attention and help.
> 
> Easy one: just use the argument plot=FALSE and hist will produce the 
> counts etc for you
> 
> David Scott

Well, there's a slightly nicer way than that! (Don't forget that
we're competing with Excel here ... ).

Since the value of hist() includes breakpoints and counts,
you can get the plot and the table as follows:

  set.seed(54321)
  X <- 5*rnorm(500)
  H<-hist(X)### Here you get the histogram drawn
  B<-H$breaks ; C<-H$counts ; k<-length(B)
  cbind(From=B[1:(k-1)],To=B[2:k],Count=C) ### Here bins and frequencies
# From  To Count
#[1,]  -15 -1016
#[2,]  -10  -569
#[3,]   -5   0   181
#[4,]0   5   149
#[5,]5  1071
#[6,]   10  1514

So we can indeed "get the table of bin and frequency like
in excel, together with the histogram".

Best wishes to all,
Ted.


E-Mail: (Ted Harding) <[EMAIL PROTECTED]>
Fax-to-email: +44 (0)870 094 0861
Date: 09-May-08   Time: 01:26:35
-- XFMail --

__
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

2008-05-08 Thread Jorge Ivan Velez
Hi all,

Why not only?

set.seed(54321)
 X <- 5*rnorm(500)
hist(X,label=TRUE,ylim=c(0,200))

Thanks,

Jorge



On Thu, May 8, 2008 at 8:26 PM, Ted Harding <[EMAIL PROTECTED]>
wrote:

> On 09-May-08 00:12:46, David Scott wrote:
> > On Thu, 8 May 2008, Roslina Zakaria wrote:
> >
> >> Dear R-expert,
> >> For histogram function, can we get the table of bin and
> >> frequency like in excel, together with the histogram?
> >> Therefore, we can check the number of data included.
> >> Thank you so much for your attention and help.
> >
> > Easy one: just use the argument plot=FALSE and hist will produce the
> > counts etc for you
> >
> > David Scott
>
> Well, there's a slightly nicer way than that! (Don't forget that
> we're competing with Excel here ... ).
>
> Since the value of hist() includes breakpoints and counts,
> you can get the plot and the table as follows:
>
>  set.seed(54321)
>  X <- 5*rnorm(500)
>  H<-hist(X)### Here you get the histogram drawn
>  B<-H$breaks ; C<-H$counts ; k<-length(B)
>  cbind(From=B[1:(k-1)],To=B[2:k],Count=C) ### Here bins and frequencies
> # From  To Count
> #[1,]  -15 -1016
> #[2,]  -10  -569
> #[3,]   -5   0   181
> #[4,]0   5   149
> #[5,]5  1071
> #[6,]   10  1514
>
> So we can indeed "get the table of bin and frequency like
> in excel, together with the histogram".
>
> Best wishes to all,
> Ted.
>
> 
> E-Mail: (Ted Harding) <[EMAIL PROTECTED]>
> Fax-to-email: +44 (0)870 094 0861
> Date: 09-May-08   Time: 01:26:35
> -- XFMail --
>
> __
> 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

2008-05-15 Thread Bill.Venables
This is pretty important.

With freq = TRUE the y-axis label is "Frequency" and the heights of the panels 
are equal to the frequency of the panel.  However as the panel widths you have 
requested are unequal, this implies that the *areas* of the panels, the really 
important bit, cannot be proportional to the relative frequency.  With equal 
class widths this can still happen if the heights are equal to the absolute 
frequency.

With freq = FALSE, the y-axis label is "Density", and all is well.  Areas are 
now actually equal to relative frequencies, and no one expects heights to be.  
This is why the message is telling you "Well, if you want unequal class 
intervals, don't also ask for panel heights to be equal to frequency or the 
histogram will become misleading."

Basically R is reluctant to let you shoot yourself in the foot unless you are 
really determined to do so.   


Bill Venables
CSIRO Laboratories
PO Box 120, Cleveland, 4163
AUSTRALIA

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Roslina Zakaria
Sent: Friday, 16 May 2008 4:12 PM
To: R help forum
Subject: [R] histogram

Hi r-expert,
I would like to plot histogram using frequency not density.
But I got the following warning.
 obs.hist <- 
hist(jan_data2[,4],right=FALSE,breaks=c(0,5,10,15,20,100),freq=TRUE,
+ xlab="Rain amt (mm)",ylim=c(0,3000),
+ main="Frequency of observed, Jan (1901-1990), Pooraka")
Warning message:
In plot.histogram(r, freq = freq1, col = col, border = border, angle = angle,  :
  the AREAS in the plot are wrong -- rather use freq=FALSE

I don't really understand the warning message and hope anybody can help me.
Thanks in advance for your help.  





__
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

2008-06-13 Thread jim holtman
It is hard to respond without reproducible examples.  Do
str(dat[2,23:46]) and see what it reports.  My guess is that one of
the columns is not numeric.  Find out which one it is, fix it and then
try 'hist' again.

On Fri, Jun 13, 2008 at 10:21 AM, Paul Adams <[EMAIL PROTECTED]> wrote:
> Hello everyone,
> I am trying to plot a histogram from the following code:
> dat<-read.table(file="C:\\Documents and Settings\\Owner\\My 
> Documents\\Yeast\\Yeast.txt",header=T,row.names=1)
> file.show(file="C:\\Documents and Settings\\Owner\\My 
> Documents\\Yeast\\Yeast.txt")
> x<-dat[2,23:46]
> y=mean(x,trim=0,na.rm=T)
> colMeans(dat[2,23:46])
> boxplot(dat[2,23:46])
> hist(dat[2,23:46])
> The box plot is fine but the histogram keeps giving me the error that x
> must be numeric.I am not sure what is wrong here with the instructions
> for the histogram plot.
> Any help would be appreciated
> Paul
>
>
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



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

What is the problem you are trying to solve?

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


Re: [R] histogram

2008-06-13 Thread Erik Iverson



Paul Adams wrote:

Hello everyone,
I am trying to plot a histogram from the following code:
dat<-read.table(file="C:\\Documents and Settings\\Owner\\My 
Documents\\Yeast\\Yeast.txt",header=T,row.names=1)
file.show(file="C:\\Documents and Settings\\Owner\\My 
Documents\\Yeast\\Yeast.txt")
x<-dat[2,23:46]
y=mean(x,trim=0,na.rm=T)
colMeans(dat[2,23:46])
boxplot(dat[2,23:46])
hist(dat[2,23:46])


Check what the class of your object is

class(dat[2, 23:46])

may be a data.frame. If so, you can try to convert accordingly (see 
?as.numeric)


Erik

__
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

2008-06-13 Thread Lars Fischer
Hi, 

please someone correct me, but
On 13/06/2008, 07:21, [EMAIL PROTECTED] wrote:
> dat<-read.table(file="C:\\Documents and Settings\\Owner\\My 
> Documents\\Yeast\\Yeast.txt",header=T,row.names=1)

Check mode and class of dat. read.table provided you with a dataframe
of, essentially, string data. You have to apply as.numeric where it
fits.


> x<-dat[2,23:46]
 ^
most probably here.

Regards
Lars

p.s. Your code is awfully to read, please add some spaces where
appropriate.


-- 
Lars Fischertel: +49 (0)6151 16-2889
Technische Universität Darmstadt
Fachbereich Informatik/ FG Sicherheit in der Informationstechnik
PGP FPR: A197 CBE1 91FC 0CE3 A71D  77F2 1094 CB6E CEE3 7111

__
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

2008-06-13 Thread Peter Dalgaard
jim holtman wrote:
> It is hard to respond without reproducible examples.  Do
> str(dat[2,23:46]) and see what it reports.  My guess is that one of
> the columns is not numeric.  Find out which one it is, fix it and then
> try 'hist' again.
>   
No, this will be wrong whatever the data are. The problem is that
dat[2,23:46] is a one-row dataframe, i.e. a list, which is not a numeric
vector. Possibly
hist(unlist(dat[2,23:46])) is what is wanted. I don't think the boxplot
is "fine" either, except in the sense that it does not give an error
(try boxplot(airquality[2,])).

> On Fri, Jun 13, 2008 at 10:21 AM, Paul Adams <[EMAIL PROTECTED]> wrote:
>   
>> Hello everyone,
>> I am trying to plot a histogram from the following code:
>> dat<-read.table(file="C:\\Documents and Settings\\Owner\\My 
>> Documents\\Yeast\\Yeast.txt",header=T,row.names=1)
>> file.show(file="C:\\Documents and Settings\\Owner\\My 
>> Documents\\Yeast\\Yeast.txt")
>> x<-dat[2,23:46]
>> y=mean(x,trim=0,na.rm=T)
>> colMeans(dat[2,23:46])
>> boxplot(dat[2,23:46])
>> hist(dat[2,23:46])
>> The box plot is fine but the histogram keeps giving me the error that x
>> must be numeric.I am not sure what is wrong here with the instructions
>> for the histogram plot.
>> Any help would be appreciated
>> Paul
>>
>>
>>
>>[[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>> 
>
>
>
>   


-- 
   O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - ([EMAIL PROTECTED])  FAX: (+45) 35327907

__
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 labels

2007-10-16 Thread H. Paul Benton
Dear all,

Just a quick one, hopefully. I have a histogram made from the method 
'hist()'. How do I get labels on the bars? Such that the bars will have 
the x axis on the bar, not the frequency of the point but the number of 
the point itself. To make a quick summary, I want the the numbers from 
'losses' (below) to be on the bar's.

Thanks,

Paul


hist<-hist(losses, breaks=length(losses)/2, col="red", main="Frequency 
of the first neutral losses > 5", labels=T, xlim=range(0:150))
 > length(losses)
[1] 3096
 > losses[1:50]
 [1]  7.835622  7.058985  5.932695  6.018867  9.973944  5.953848  9.004838
 [8]  9.846519  8.984468  8.898072  7.998546  6.123770  8.811126 13.859201
[15]  8.970615  5.102851  6.982555  7.891584  7.330879 10.981950 17.913884
[22]  9.996668 14.021043 12.892713 19.975109  5.979874  6.044765  9.986221
[29] 10.045082 13.981433 11.963917 15.013278 14.950140 16.990841 15.018136
[36] 12.944700 46.960090 27.995546 76.978781  7.140487  8.704401  6.043193
[43]  8.030726  9.085684  8.900260 27.018362  8.449553  8.007181  5.954782
[50]  8.108130

__
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

2009-07-03 Thread Uwe Ligges



aledanda wrote:

Hallo,

How can I have the control of the width of each bin in the histogram?
I would like to plot my data modifying the number and the width of the bins.

Is there a good pdf or manual where i can learn to use the plot/hist in R
very well?


See
 ?hist
and its argument "breaks".

Uwe Ligges




I find the help not always clear

Thanks a lot


Ale


__
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

2009-07-03 Thread Mark Knecht
On 7/3/09, aledanda  wrote:
>
>  Hallo,
>
>  How can I have the control of the width of each bin in the histogram?
>  I would like to plot my data modifying the number and the width of the bins.
>
>  Is there a good pdf or manual where i can learn to use the plot/hist in R
>  very well?
>  I find the help not always clear
>
>  Thanks a lot
>
>
>  Ale

Possibly somewhat like this?

http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=89

- Mark

__
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

2009-07-03 Thread Greg Snow
I addition to the other responses you have received, you may want to play with 
the run.hist.demo function in the TeachingDemos package to learn more.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of aledanda
> Sent: Friday, July 03, 2009 9:55 AM
> To: r-help@r-project.org
> Subject: [R] Histogram
> 
> 
> Hallo,
> 
> How can I have the control of the width of each bin in the histogram?
> I would like to plot my data modifying the number and the width of the
> bins.
> 
> Is there a good pdf or manual where i can learn to use the plot/hist in
> R
> very well?
> I find the help not always clear
> 
> Thanks a lot
> 
> 
> Ale
> --
> View this message in context: http://www.nabble.com/Histogram-
> tp24325261p24325261.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.


[R] histogram scaling

2009-08-18 Thread rajesh j
Hi,

I'm drawing two histograms in the same plot.However, my point of comparison
is the difference in their x coordinates.But my problem is one histogram is
much taller than the other.How can I get them both to the same height?

-- 
Rajesh.J

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

2009-08-20 Thread Conrad Addo
I'm trying to create a histogram from the following code, but my data keeps
adding the Num vector and plotting that.  My data in the CSV file is just
one vector.  Does anyone know why?

Thanks
Conrad


SPXdf = data.frame(read.csv(file = "SPX.csv", header = TRUE, sep = ",", dec
= ".", fill = TRUE))

Max = max(SPXdf[,2])
Min = min(SPXdf[,2])
Count = length(SPXdf[,2])
sig = sd(SPXdf[,2])

BinSize = (3.5*sig)/(Count^(1/3))
BinNum = (Max - Min)/(BinSize)
Bins = seq(Min,Max,by = BinSize)
Count2 = length(Bins)
Num = mat.or.vec(1,Count2)


for (i in 1:Count){

for (j in 1:Count2){


if ((SPXdf[i,2] < Bins[j]))
{Num[j] = Num[j] + 1}
}

}

barplot(Num,Bins, xlab = "SPXdf", ylab = "Frequency")

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

2008-07-17 Thread Xin
Dear All:

  I am trying to plot a series of data using histogram plot. But I want to 
change the default of setting for histogram plot. For example, I want to set 
frequency plot starting with zero.

   Many Thanks

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

2008-08-19 Thread jim holtman
Is this what you want:

cuts <- c(0,209,429,719,1500)
x <- runif(1000,0,1447)
barplot(table(cut(x, breaks=cuts)))



On Tue, Aug 19, 2008 at 4:17 PM, Ben Cox <[EMAIL PROTECTED]> wrote:
> I am trying to produce frequencies in defined intervals however I can't seem
> to figure out how to get R to bin my data the way I want it to.
>
>
>
> I have several thousand lengths of fish that I want to be binned as follows:
>
>
>
>
> Ex.
>
>
>
> Length  Bin
>
>
>
> 209 200
>
> 219 210
>
> 431 430
>
> 727 720
>
>
>
> That is, bins with any length equal to or greater than the lower cutoff, but
> smaller than the next higher cutoff should be included.  I have tried using
> the right=FALSE and include.lowest in the hist function but it still puts
> lengths that is greater than the cutoff into the next bin.
>
> All software seems to bin right, but fish nerds do it a little different.
>
>
>
>
>
>
>
> Thanks!
>
> Ben Cox
>
> Graduate Research Assistant (M.S.)
>
> Montana Cooperative Fishery Research Unit
>
> Montana State University
>
> PO Box 173460
>
> Bozeman, MT 59717
>
> (406)994-6643
>
>
>
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



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

What is the problem that you are trying to solve?

__
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 NAs

2008-01-18 Thread darteta001
Dear list,

I have a categorical variable in a data.frame that I would like to 
plot using a histogram to show number of events. Values are 0, 1 and 
some NAs. I can´t make the hist() function to 
1) include a column with the number of NAs
2) have the x axis to be categorical, I always get 0, 0.2, 0.4,... 1 
divisions

Can anyone help me?

This is my code. "database" is my data.frame and "Event" is my 
variable.
attach(database)
hist(Event, col = 2, main = "Number of Events"))

Thanks in advance,

David

__
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 height

2009-02-01 Thread Jim Lemon

Brendan Cusick wrote:

Hello.  I have what I'm sure is a very simple question.  Hopefully someone
can help.  I can't seem to find the maximum height of a histogram.  In
matlab it would be simple to say max(hist(x, 100)), but this doesn't seem to
work in R.  Any input would be greatly appreciated.
  

Hi Brendan,
Try:
max(hist(x,100)$counts,na.rm=TRUE)

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 height

2009-02-01 Thread Brendan Cusick
Jim, you are a genius.  Thanks for the help.

Brendan

On Sun, Feb 1, 2009 at 5:44 AM, Jim Lemon  wrote:

>  Brendan Cusick wrote:
>
>> Hello.  I have what I'm sure is a very simple question.  Hopefully someone
>> can help.  I can't seem to find the maximum height of a histogram.  In
>> matlab it would be simple to say max(hist(x, 100)), but this doesn't seem
>> to
>> work in R.  Any input would be greatly appreciated.
>>
>>
> Hi Brendan,
> Try:
> max(hist(x,100)$counts,na.rm=TRUE)
>
> 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.


[R] histogram tick labels

2008-06-08 Thread Lawrence Hanser
Dear Friends,

I am doing a rather simple histogram on a vector of data, MR.  I set
breaks for the intervals:

hist(MR,breaks=c(0, 2.9, 5.9, 8.9, 11.9,14.9, 17.9, 20.9))

My question is, how do I change the labels on the tick marks?  I have
looked at ?hist and can't find a clue...

Thanks in advance.

Larry

__
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 gaps

2008-06-10 Thread Creighton, Sean
Hi

I consider myself not a complete beginner in R, however an elegant
solution to this problem stumps me. I have a fairly long time series of
6 or so points, I need to gather the data to create a histogram of
the length of continuous zero periods in a data set. 

So image the data looks like this (where as a pre-condition all numbers
are single digit so assume commas if you which, I have the time series
properly formatted in a zoo object)

4324535235235235325233503343253532523523522352352353253225325300
002352352332552533252353200325235235

I should get the following zero periods out: 

43245352352352353252335 <0>
33432535325235235223523523532532253253 <> 23523523325525332523532
<00> 325235235

So I have three entries for my histogram 5,4 and 2. Now can anyone give
me any tips that doesn't involve using a loop which will be quite time
consuming? Is there some function in a libray that already does
something like this?

Thanks
Sean

__
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 colors

2007-09-17 Thread Alberto Monteiro
Is there a simple way to plot a histogram with colors?

For example, suppose I generate random points in the
N(2,1) distribution:

  x <- rnorm(10, mean = 2, sd = 1)

Now I would like to plot the histogram:

  hist(x)

but I would like to show the bars with x < 0 in red, and the
bars with x >= 0 in lightgreen. Is there any simple way to
do it?

I think I can do it in two steps:

  x.hist <- hist(x, plot=FALSE)
  plot(x.hist, col=c(rep("red", 5), rep("green", 12)))

but maybe a more direct way is available.

Alberto Monteiro

__
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 labels

2007-10-18 Thread H. Paul Benton
Jim Lemon wrote:
> Hi Paul,
> It looks like you have a 1548 bar histogram, which means that you 
> can't even resolve the bars on the standard display, much less 
> annotate them. 

umm yes but I know that I only want to see everything from 0 : 150 so 
it's ends up only being 300bar's which I agree is still a lot but 
resolvable.

hist<-hist(losses, breaks=length(losses)/2, col="red", main="Frequency 
of the first neutral losses > 5", labels=T, xlim=range(0:150))
> I confess that I can't figure out what you are trying to do, so maybe 
> a more informative example would help.
I just want the labels from hist$breaks on the bars, not the frequency 
like "labels=TRUE" gives you. Is there a different histogram I can use 
or something?

Thank,

Paul
>
> Jim
>
> H. Paul Benton wrote:
> Dear all,
>
> Just a quick one, hopefully. I have a histogram made from the method 
> 'hist()'. How do I get labels on the bars? Such that the bars will 
> have the x axis on the bar, not the frequency of the point but the 
> number of the point itself. To make a quick summary, I want the the 
> numbers from 'losses' (below) to be on the bar's.
>
> Thanks,
>
> Paul
>
>
> hist<-hist(losses, breaks=length(losses)/2, col="red", main="Frequency 
> of the first neutral losses > 5", labels=T, xlim=range(0:150))
>  > length(losses)
> [1] 3096
>  > losses[1:50]
>  [1]  7.835622  7.058985  5.932695  6.018867  9.973944  5.953848  
> 9.004838
>  [8]  9.846519  8.984468  8.898072  7.998546  6.123770  8.811126 
> 13.859201
> [15]  8.970615  5.102851  6.982555  7.891584  7.330879 10.981950 
> 17.913884
> [22]  9.996668 14.021043 12.892713 19.975109  5.979874  6.044765  
> 9.986221
> [29] 10.045082 13.981433 11.963917 15.013278 14.950140 16.990841 
> 15.018136
> [36] 12.944700 46.960090 27.995546 76.978781  7.140487  8.704401  
> 6.043193
> [43]  8.030726  9.085684  8.900260 27.018362  8.449553  8.007181  
> 5.954782
> [50]  8.108130
>

__
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 labels

2007-10-18 Thread hadley wickham
Hi Paul,

Why do you want to do that?  Maybe you could publish table along side
your graph if you want people to be able to read the raw numbers.

Hadley

On 10/16/07, H. Paul Benton <[EMAIL PROTECTED]> wrote:
> Dear all,
>
> Just a quick one, hopefully. I have a histogram made from the method
> 'hist()'. How do I get labels on the bars? Such that the bars will have
> the x axis on the bar, not the frequency of the point but the number of
> the point itself. To make a quick summary, I want the the numbers from
> 'losses' (below) to be on the bar's.
>
> Thanks,
>
> Paul
>
>
> hist<-hist(losses, breaks=length(losses)/2, col="red", main="Frequency
> of the first neutral losses > 5", labels=T, xlim=range(0:150))
>  > length(losses)
> [1] 3096
>  > losses[1:50]
>  [1]  7.835622  7.058985  5.932695  6.018867  9.973944  5.953848  9.004838
>  [8]  9.846519  8.984468  8.898072  7.998546  6.123770  8.811126 13.859201
> [15]  8.970615  5.102851  6.982555  7.891584  7.330879 10.981950 17.913884
> [22]  9.996668 14.021043 12.892713 19.975109  5.979874  6.044765  9.986221
> [29] 10.045082 13.981433 11.963917 15.013278 14.950140 16.990841 15.018136
> [36] 12.944700 46.960090 27.995546 76.978781  7.140487  8.704401  6.043193
> [43]  8.030726  9.085684  8.900260 27.018362  8.449553  8.007181  5.954782
> [50]  8.108130
>
> __
> 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.
>


-- 
http://had.co.nz/

__
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 scaling

2009-08-19 Thread Chris Friedl

Hey, Rajesh

I bit light on detail here. Being a mind reader is not an R-help
prerequisite. However since I have been working on histograms today and
you've just posted a question using ggplot, let me guess that its ggplot you
are refering to. Then here is an example, which you can find in my post a
few posts previous to yours. I've added scale_ commands to restrict the x
and y scales. Actually in this example both histograms get plotted on the
same y-scale automatically so that command can be removed.

Check out the ggplot on line reference http://had.co.nz/ggplot2/ and book
http://cran.r-project.org/web/packages/ggplot2/ggplot2.pdf

hth


require(ggplot2)
x <- data.frame(value=rnorm(5000, mean=0), case="A")
y <- data.frame(value=rnorm(5000, mean=3), case="B")
xy <- rbind(x, y)
ggplot(xy, aes(x=value, fill=case, group=case)) + geom_histogram(alpha=0.5,
binwidth=0.1, position="identity") + scale_x_continuous(limits=c(-2,3)) +
scale_y_continuous(limits=c(0,250))




rajesh j wrote:
> 
> Hi,
> 
> I'm drawing two histograms in the same plot.However, my point of
> comparison
> is the difference in their x coordinates.But my problem is one histogram
> is
> much taller than the other.How can I get them both to the same height?
> 
> -- 
> Rajesh.J
> 
>   [[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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/histogram-scaling-tp25038602p25038798.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 problem

2009-08-20 Thread Petr PIKAL
Hi

R does what you said to it it shall do! 

Without  **reproducible** code and explanation what you did, what you get 
and what you **expect** to get it would be quite complicated task to 
understand what your code actually do.

e.g. this

> > for (i in 1:Count){
> >
> > for (j in 1:Count2){
> >
> >
> > if ((SPXdf[i,2] < Bins[j]))
> > {Num[j] = Num[j] + 1}
> > }
> >
> > }

add 1 to Num[j] each time when SPXdf[i,2] < Bins[j] but without real 
numbers and understanding why you can not use hist and are making your own 
histogram function it is hard to say what do you want. 
I am pretty sure you are inventing a wheel.

Regards
Petr

Conrad Addo  napsal dne 20.08.2009 16:29:36:

> Petr
> 
> Actually I wanted to find why the NUm vector was adding incrementally, 
not 
> about the CSV.
> 
> Thanks

> On Thu, Aug 20, 2009 at 3:24 PM, Petr PIKAL  
wrote:
> Hi
> 
> r-help-boun...@r-project.org napsal dne 20.08.2009 15:33:38:
> 
> > I'm trying to create a histogram from the following code, but my data
> keeps
> > adding the Num vector and plotting that.  My data in the CSV file is
> just
> > one vector.  Does anyone know why?

> Well, I think that only you know why CSV file is just one vector, (which 
I
> do not believe as SPXdf[,2] does not coplain).
> 
> >
> > Thanks
> > Conrad
> >
> >
> > SPXdf = data.frame(read.csv(file = "SPX.csv", header = TRUE, sep = 
",",
> dec
> > = ".", fill = TRUE))
> 
> 
> > SPXdf = data.frame(read.csv(file = "SPX.csv", header = TRUE, sep = 
",",
> dec
> + = ".", fill = TRUE))
> Error in file(file, "r") : cannot open the connection
> In addition: Warning message:
> In file(file, "r") : cannot open file 'SPX.csv': No such file or 
directory
> > Max = max(SPXdf[,2])
> Error: object 'SPXdf' not found
> > Min = min(SPXdf[,2])
> E
> 
> I can not retrieve the data, it throws an error.
> 
> >
> > Max = max(SPXdf[,2])
> > Min = min(SPXdf[,2])
> > Count = length(SPXdf[,2])
> > sig = sd(SPXdf[,2])
> >
> > BinSize = (3.5*sig)/(Count^(1/3))
> > BinNum = (Max - Min)/(BinSize)
> > Bins = seq(Min,Max,by = BinSize)
> > Count2 = length(Bins)
> > Num = mat.or.vec(1,Count2)
> >
> >
> > for (i in 1:Count){
> >
> > for (j in 1:Count2){
> >
> >
> > if ((SPXdf[i,2] < Bins[j]))
> > {Num[j] = Num[j] + 1}
> > }
> >
> > }
> >
> > barplot(Num,Bins, xlab = "SPXdf", ylab = "Frequency")

> R does what you require. You want barplot of Num vector with width
> according to Bin vector.
> 
> Just as a curiosity, does hist(SPXdf[,2]) show a histogram?
> 
> Regards
> Petr
> 
> 
> >
> >[[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 default

2008-07-18 Thread jim holtman
Doesn't it now?  PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html and provide commented,
minimal, self-contained, reproducible code.

On Thu, Jul 17, 2008 at 8:26 AM, Xin <[EMAIL PROTECTED]> wrote:
> Dear All:
>
>  I am trying to plot a series of data using histogram plot. But I want to 
> change the default of setting for histogram plot. For example, I want to set 
> frequency plot starting with zero.
>
>   Many Thanks
>
>   Xin
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



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

What is the problem you are trying to solve?

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


[R] Histogram colours in lattice.

2008-10-07 Thread Rolf Turner


I am trying to do a histogram lattice plot and I would like the
histogram to be filled with a different colour in each panel.

Note:  I want every bar in each histogram to be the same colour,
but that there should be different colours *between* histograms.

Can't seem to get this to work.  I thought that something like
the following would be a goer:

set.seed(42)
X <- rnorm(200)
A <- factor(sample(letters[1:5],200,TRUE))
DF <- data.frame(x=X,a=A)
print(histogram(~x|a,data=DF,col=2:6,type="count",
panel=function(x,...,subscripts,col) {
panel.histogram(x,...,col=col[subscripts])
}))

However it somewhat mysteriously colours the first bar/rectangle
of the histogram appropriately in the last three panels, leaving
all of the others blank, and leaves all bars blank in the first
two panels.

Can I do what I want?  How?  Thanks for any advice (other than
``Go stick your head in a pig.'' :-) )

cheers,

Rolf Turner


##
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

__
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 frequency table?

2008-01-11 Thread Brian Nguyen
Hi, I've had some trouble figuring out how to produce a histogram in R directly 
given a frequency table or relative frequency table. I've looked through the 
documentation and mailing list, and have only found information on producing 
histograms given the original data set. Any help would be appreciated!

An example of what I'd like to do would be to take the following frequency 
table:

Class   FreqRel Freq
=
[1,2)11/3
[2,3)22/3

and translate it into the corresponding histogram.



- Brian Nguyen
   
-

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

2008-01-18 Thread Gustaf Rydevik
On Jan 18, 2008 4:49 PM,  <[EMAIL PROTECTED]> wrote:
> Dear list,
>
> I have a categorical variable in a data.frame that I would like to
> plot using a histogram to show number of events. Values are 0, 1 and
> some NAs. I can´t make the hist() function to
> 1) include a column with the number of NAs
> 2) have the x axis to be categorical, I always get 0, 0.2, 0.4,... 1
> divisions
>
> Can anyone help me?
>
> This is my code. "database" is my data.frame and "Event" is my
> variable.
> attach(database)
> hist(Event, col = 2, main = "Number of Events"))
>
> Thanks in advance,
>
> David


Please read ?hist, especially the line:

"Typical plots with vertical bars are not histograms. Consider barplot
or plot(*, type = "h") for such bar plots. ". But no worry, I've mixed
them up myself a number of times.

To get a column of NA's, see the following:
###Example:
sample.data<-as.factor(sample(c(1,0,NA),100,replace=T))
sample.data<-as.character(sample.data)
sample.data[is.na(sample.data)]<-" NA"
sample.data<-factor(sample.data)
plot(sample.data)
#

/Gustaf


-- 
Gustaf Rydevik, M.Sci.
tel: +46(0)703 051 451
address:Essingetorget 40,112 66 Stockholm, SE
skype:gustaf_rydevik

__
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 NAs

2008-01-18 Thread hadley wickham
> "Typical plots with vertical bars are not histograms. Consider barplot
> or plot(*, type = "h") for such bar plots. ". But no worry, I've mixed
> them up myself a number of times.

Or you can use ggplot2, which will do the right thing regardless of
whether you have continuous or categorical data:

library(ggplot2)
qplot(sample.data, geom="histogram")
qplot(rnorm(100), geom="histogram")

Hadley

-- 
http://had.co.nz/

__
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 Label Font Size

2008-04-14 Thread Sue Lee

Hi!
I'm having a trouble changing font size of histogram label.
I have tried help(hist), but I couldn't find anything explain how to fix 
label's font size.
Could you help me please?

Thank you. 

_
Going green? See the top 12 foods to eat organic.

1N1653A
[[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() with "Date" class?

2008-05-08 Thread Ola Caster
Dear help list,

Is it possible to draw lattice histograms (i.e. use the histogram() function
and not the hist() function) with objects of class "Date"?

I've tried solutions like

histogram(~date, data=my.data, breaks="months")

but it doesn't seem to work.

Any suggestions are welcome.

Many thanks
Ola Caster

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

2008-06-09 Thread S Ellison
Lawrence,

use hist(..., axes=F)
then put your own axis on with axis(1,...)
Example:
y<-rnorm(200)
hist(y,axes=F)
axis(2)
axis(1, at=seq(-3,3,1))

Steve E

>>> "Lawrence Hanser" <[EMAIL PROTECTED]> 06/09/08 7:02 AM >>>
Dear Friends,

I am doing a rather simple histogram on a vector of data, MR.  I set
breaks for the intervals:

hist(MR,breaks=c(0, 2.9, 5.9, 8.9, 11.9,14.9, 17.9, 20.9))

My question is, how do I change the labels on the tick marks?  I have
looked at ?hist and can't find a clue...

Thanks in advance.

Larry

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


***
This email and any attachments are confidential. Any use...{{dropped:8}}

__
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 gaps

2008-06-10 Thread Chuck Cleland

On 6/10/2008 9:23 AM, Creighton, Sean wrote:

Hi

I consider myself not a complete beginner in R, however an elegant
solution to this problem stumps me. I have a fairly long time series of
6 or so points, I need to gather the data to create a histogram of
the length of continuous zero periods in a data set. 


So image the data looks like this (where as a pre-condition all numbers
are single digit so assume commas if you which, I have the time series
properly formatted in a zoo object)

4324535235235235325233503343253532523523522352352353253225325300
002352352332552533252353200325235235

I should get the following zero periods out: 


43245352352352353252335 <0>
33432535325235235223523523532532253253 <> 23523523325525332523532
<00> 325235235

So I have three entries for my histogram 5,4 and 2. Now can anyone give
me any tips that doesn't involve using a loop which will be quite time
consuming? Is there some function in a libray that already does
something like this?


  How about rle()?  For example:

X <- sample(0:9, 6, replace=TRUE)

table(rle(X == 0)[[1]][rle(X == 0)[[2]]])

   1234
4813  490   493

hist(rle(X == 0)[[1]][rle(X == 0)[[2]]])

?rle


Thanks
Sean

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


--
Chuck Cleland, Ph.D.
NDRI, Inc. (www.ndri.org)
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894

__
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/Bar plot graph

2008-02-06 Thread Senthil Kumar M
Hi,

I have the following data:

> Myvalues
 Gene  ES   MEF Embryo  ESHyp
1   GeneA   -0.38509507  0.00 1.6250  1.7039921
2   GeneB0.06262914  0.00 1.6250 -0.272033
and so on...

I want to plot the expression values of GeneA and GeneB in the
different cell/embryo/conditions (columns 2:5 above). Now, if I do:

>library(ggplot2)
> qplot(x=Gene, Embryo, geom = "bar")

I get a plot of GeneA, B...so on only for the Embryo (ie column 4).

How do I get to plot multiple instances of Y for the same value of X ?

I have tried to find this out myself, but it is a bit confusing and
so, I am writing to the list as a last resort.

Any help or guidance will be much appreciated.

TIA,

Senthil

__
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 for integer data

2008-03-27 Thread Erwann.Rogard
hi,
 
library(lattice)
x<-c(-1,-1,-1,0,0,0,0,1,1,2)
rng<-range(x)
histogram(x,endpoints=c(rng[1]-0.5,rng[2]+0.5),nint=length(unique(x)))
 
instead of contiguous bins, i'd like spaces between them to indicate
that the data is discrete, or even better, line segments positioned at
integer values.
i know how to do this with plot, but i need it with histogram, so that
in more complicated contexts i can use histogram(~x| f1 * f2)
 
thanks!
 
 

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

2007-09-17 Thread Ross Darnell
Not really but a better plot call would be


plot(x.hist,col=ifelse(x.hist$breaks<0,"red","green"))

Ross Darnell


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Alberto Monteiro
Sent: Tuesday, 18 September 2007 6:12 AM
To: [EMAIL PROTECTED]
Subject: [R] Histogram with colors

Is there a simple way to plot a histogram with colors?

For example, suppose I generate random points in the
N(2,1) distribution:

  x <- rnorm(10, mean = 2, sd = 1)

Now I would like to plot the histogram:

  hist(x)

but I would like to show the bars with x < 0 in red, and the
bars with x >= 0 in lightgreen. Is there any simple way to
do it?

I think I can do it in two steps:

  x.hist <- hist(x, plot=FALSE)
  plot(x.hist, col=c(rep("red", 5), rep("green", 12)))

but maybe a more direct way is available.

Alberto Monteiro

__
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 with colors

2007-09-17 Thread hadley wickham
On 9/17/07, Alberto Monteiro <[EMAIL PROTECTED]> wrote:
> Is there a simple way to plot a histogram with colors?
>
> For example, suppose I generate random points in the
> N(2,1) distribution:
>
>   x <- rnorm(10, mean = 2, sd = 1)
>
> Now I would like to plot the histogram:
>
>   hist(x)
>
> but I would like to show the bars with x < 0 in red, and the
> bars with x >= 0 in lightgreen. Is there any simple way to
> do it?

You can do this with ggplot:

install.packages("ggplot2")
library(ggplot2)
qplot(x, geom="histogram", data=data.frame(x), fill = factor(x >= 0))

You can find out more at http://had.co.nz/ggplot2.

Hadley

__
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 colors

2007-09-18 Thread S Ellison
>>> "Alberto Monteiro" <[EMAIL PROTECTED]> 17/09/2007 21:11:51 >>>
>Is there a simple way to plot a histogram with colors?
>
>I think I can do it in two steps:
>
>  x.hist <- hist(x, plot=FALSE)
>  plot(x.hist, col=c(rep("red", 5), rep("green", 12)))
>
>but maybe a more direct way is available.

Not really, unless you specify breaks= in the histogram call. You will need to 
know the number of bins to specify the colours correctly, so you need a 
histogram object.

But you can use the histogram object itself to choose which bars to colour:
 x<-rnorm(150)
x.hist<-hist(x, plot=F)
plot(x.hist, col=ifelse(x.hist$mids>0,"green","red"))

$mids holds the midpoints of the bins, so it will always give you a vector of 
the right length for the colours.

You can compress this into one line:
plot(x.hist<-hist(x, plot=F), col=ifelse(x.hist$mids>0,"green","red"))

but it's really the same number of operations, so it gains little.


Steve ellison


***
This email and any attachments are confidential. Any use, co...{{dropped}}

__
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 and moving average

2009-04-14 Thread Vallat Morgan
Hi everyone,

I have a 'basic' issue and hope someone has a bit of code to solve it. I
have two populations plotted as histograms on the same figure. Basically I want 
to add the moving average (based on hist) for both populations on my graph. I'm 
also interested in the x coordinate of the curves intersection. Any thoughts?

Your help would be much appreciated!
Thanks,

Gan
__
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 inset into another histogram

2008-06-18 Thread Victor Homar

Dear R users and helpers,

I'm trying to find an example of a histogram plot as an inset (upper 
right or left corner) of another histogram.


Anyone has an example of that?

Thanks for your help,

Víctor.

--
---
Víctor Homar Santaner
Grup de Meteorologia

Edif. Mateu Orfila  Tel: +34 971 17 1376
Universitat de les Illes BalearsFax: +34 971 17 3426
07122 Palma de Mallorca (SPAIN) Email: [EMAIL PROTECTED]

 Knowledge is contagious. Infect truth.

__
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 - freq=FALSE - density computation

2008-08-07 Thread Jörg Groß

Hi,

I don't understand what

hist(x, freq=FALSE)

does.


At first I thought it would be just the relative frequencies instead  
of the absolute frequencies,

by just computing "frequencies / n" in every category.

But with a small dataset the y-values (densities) don't sum to one.

Is there a way to get the histogram doing that?
Or what is the idea of this density-computation?


I hope the question is not too stupid...

__
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 colours in lattice.

2008-10-07 Thread hadley wickham
On Tue, Oct 7, 2008 at 8:54 PM, Rolf Turner <[EMAIL PROTECTED]> wrote:
>
> I am trying to do a histogram lattice plot and I would like the
> histogram to be filled with a different colour in each panel.
>
> Note:  I want every bar in each histogram to be the same colour,
> but that there should be different colours *between* histograms.
>
> Can't seem to get this to work.  I thought that something like
> the following would be a goer:
>
> set.seed(42)
> X <- rnorm(200)
> A <- factor(sample(letters[1:5],200,TRUE))
> DF <- data.frame(x=X,a=A)
> print(histogram(~x|a,data=DF,col=2:6,type="count",
> panel=function(x,...,subscripts,col) {
>panel.histogram(x,...,col=col[subscripts])
> }))
>
> However it somewhat mysteriously colours the first bar/rectangle
> of the histogram appropriately in the last three panels, leaving
> all of the others blank, and leaves all bars blank in the first
> two panels.
>
> Can I do what I want?  How?  Thanks for any advice (other than
> ``Go stick your head in a pig.'' :-) )

You could always use ggplot2:

library(ggplot2)
qplot(X, data=DF, geom="histogram", fill=A, facets = . ~ a, binwidth=0.5)

Hadley

-- 
http://had.co.nz/

__
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 colours in lattice.

2008-10-07 Thread Deepayan Sarkar
On 10/7/08, Rolf Turner <[EMAIL PROTECTED]> wrote:
>
>  I am trying to do a histogram lattice plot and I would like the
>  histogram to be filled with a different colour in each panel.
>
>  Note:  I want every bar in each histogram to be the same colour,
>  but that there should be different colours *between* histograms.
>
>  Can't seem to get this to work.  I thought that something like
>  the following would be a goer:
>
>  set.seed(42)
>  X <- rnorm(200)
>  A <- factor(sample(letters[1:5],200,TRUE))
>  DF <- data.frame(x=X,a=A)
>  print(histogram(~x|a,data=DF,col=2:6,type="count",
>  panel=function(x,...,subscripts,col) {
> panel.histogram(x,...,col=col[subscripts])
>  }))
>
>  However it somewhat mysteriously colours the first bar/rectangle
>  of the histogram appropriately in the last three panels, leaving
>  all of the others blank, and leaves all bars blank in the first
>  two panels.

That's because you are ending up with 'col[subscripts]' being a
vector, most elements of which are NA.

>  Can I do what I want?  How?

print(histogram(~x|a,data=DF,col=2:6,type="count",
  panel=function(x,...,col) {
 panel.histogram(x,...,col=col[packet.number()])
}))

-Deepayan

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


Re: [R] Histogram colours in lattice.

2008-10-08 Thread Rolf Turner


On 8/10/2008, at 5:16 PM, Deepayan Sarkar wrote:


On 10/7/08, Rolf Turner <[EMAIL PROTECTED]> wrote:


 I am trying to do a histogram lattice plot and I would like the
 histogram to be filled with a different colour in each panel.

 Note:  I want every bar in each histogram to be the same colour,
 but that there should be different colours *between* histograms.

 Can't seem to get this to work.  I thought that something like
 the following would be a goer:

 set.seed(42)
 X <- rnorm(200)
 A <- factor(sample(letters[1:5],200,TRUE))
 DF <- data.frame(x=X,a=A)
 print(histogram(~x|a,data=DF,col=2:6,type="count",
 panel=function(x,...,subscripts,col) {
panel.histogram(x,...,col=col[subscripts])
 }))

 However it somewhat mysteriously colours the first bar/rectangle
 of the histogram appropriately in the last three panels, leaving
 all of the others blank, and leaves all bars blank in the first
 two panels.


That's because you are ending up with 'col[subscripts]' being a
vector, most elements of which are NA.


 Can I do what I want?  How?


print(histogram(~x|a,data=DF,col=2:6,type="count",
  panel=function(x,...,col) {
 panel.histogram(x,...,col=col[packet.number()])
}))


Works like a charm.  Thanks very much.  I guess I thought
I roughly understood what ``subscripts'' meant, and it seems
I don't understand at all.  And I didn't know *anything* about
``packet.number()''.  It would seem that I need to read your
book --- are these things explained there?

Thanks again.

cheers,

Rolf Turner

##
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

__
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 colours in lattice.

2008-10-08 Thread Deepayan Sarkar
On Wed, Oct 8, 2008 at 12:15 PM, Rolf Turner <[EMAIL PROTECTED]> wrote:
>
> On 8/10/2008, at 5:16 PM, Deepayan Sarkar wrote:
>
>> On 10/7/08, Rolf Turner <[EMAIL PROTECTED]> wrote:
>>>
>>>  I am trying to do a histogram lattice plot and I would like the
>>>  histogram to be filled with a different colour in each panel.
>>>
>>>  Note:  I want every bar in each histogram to be the same colour,
>>>  but that there should be different colours *between* histograms.
>>>
>>>  Can't seem to get this to work.  I thought that something like
>>>  the following would be a goer:
>>>
>>>  set.seed(42)
>>>  X <- rnorm(200)
>>>  A <- factor(sample(letters[1:5],200,TRUE))
>>>  DF <- data.frame(x=X,a=A)
>>>  print(histogram(~x|a,data=DF,col=2:6,type="count",
>>>  panel=function(x,...,subscripts,col) {
>>>panel.histogram(x,...,col=col[subscripts])
>>>  }))
>>>
>>>  However it somewhat mysteriously colours the first bar/rectangle
>>>  of the histogram appropriately in the last three panels, leaving
>>>  all of the others blank, and leaves all bars blank in the first
>>>  two panels.
>>
>> That's because you are ending up with 'col[subscripts]' being a
>> vector, most elements of which are NA.
>>
>>>  Can I do what I want?  How?
>>
>> print(histogram(~x|a,data=DF,col=2:6,type="count",
>>  panel=function(x,...,col) {
>> panel.histogram(x,...,col=col[packet.number()])
>> }))
>
>Works like a charm.  Thanks very much.  I guess I thought
>I roughly understood what ``subscripts'' meant, and it seems
>I don't understand at all.  And I didn't know *anything* about
>``packet.number()''.  It would seem that I need to read your
>book --- are these things explained there?

Yes, but note that your use case is somewhat nonstandard, and is not
one directly addressed either in my book, or in the older Trellis
literature (as far as I know).

packet.number() is explained adequately in the help page. The
subscripts concept is very useful, but definitely poses a challenge to
many users (it took me a while to understand all its implications
too). I don't know how to explain it in simple terms, except to say
that it is the per-panel row indices with respect to the original data
source. For example,


> foo <- xyplot(10:1 ~ 1:10 | gl(2, 1, 10), subscripts = TRUE)
> str(trellis.panelArgs(foo, 1))
List of 3
 $ x : int [1:5] 1 3 5 7 9
 $ y : int [1:5] 10 8 6 4 2
 $ subscripts: int [1:5] 1 3 5 7 9
> str(trellis.panelArgs(foo, 2))
List of 3
 $ x : int [1:5] 2 4 6 8 10
 $ y : int [1:5] 9 7 5 3 1
 $ subscripts: int [1:5] 2 4 6 8 10

-Deepayan

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


Re: [R] Histogram from frequency table?

2008-01-11 Thread Duncan Murdoch
On 1/11/2008 8:55 AM, Brian Nguyen wrote:
> Hi, I've had some trouble figuring out how to produce a histogram in R 
> directly given a frequency table or relative frequency table. I've looked 
> through the documentation and mailing list, and have only found information 
> on producing histograms given the original data set. Any help would be 
> appreciated!
> 
> An example of what I'd like to do would be to take the following frequency 
> table:
> 
> Class   FreqRel Freq
> =
> [1,2)11/3
> [2,3)22/3
> 
> and translate it into the corresponding histogram.


The way hist() works is to create an object of class histogram, and then 
it plots it.  You could create the object directly.  For the example 
above, it would go like this:

myhist <- list(breaks = 1:3, counts = 1:2, density = (1:2)/3, xname="X")
class(myhist) <- "histogram"
plot(myhist)

If you know you want a freq=TRUE histogram, you can skip density; if you 
know you want a freq=FALSE histogram, you can skip counts.  You can see 
in the source to graphics:::plot.histogram that the "equidist" component 
of the histogram isn't really needed.

Duncan Murdoch

__
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 Label Font Size

2008-04-14 Thread Henrique Dallazuanna
I think that you can edit the source code of histogram for this:

myhist <- getS3method("plot", "histogram")
body(myhist)[9] <-
parse(text = c(capture.output(body(myhist)[9])[-6],
 "} else labels, adj = c(0.5, -0.5), ...)"))

r <- hist(islands, plot = F)
myhist(r, labels = T, cex = 0.8)

On Mon, Apr 14, 2008 at 4:35 PM, Sue Lee <[EMAIL PROTECTED]> wrote:

>
> Hi!
> I'm having a trouble changing font size of histogram label.
> I have tried help(hist), but I couldn't find anything explain how to fix
> label's font size.
> Could you help me please?
>
> Thank you.
>
> _
> Going green? See the top 12 foods to eat organic.
>
> 1N1653A
>[[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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[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 Label Font Size

2008-04-14 Thread Robert Baer
Here's an example to make the text 18 point.  You can set ps=6 to make small 
text.
x=rnorm(100)
opar=par(ps=18)  # Make text 18 point
hist(x)
opar

Rob Baer

- Original Message - 
From: "Sue Lee" <[EMAIL PROTECTED]>
To: 
Sent: Monday, April 14, 2008 2:35 PM
Subject: [R] Histogram Label Font Size


>
> Hi!
> I'm having a trouble changing font size of histogram label.
> I have tried help(hist), but I couldn't find anything explain how to fix 
> label's font size.
> Could you help me please?
>
> Thank you.
>
> _
> Going green? See the top 12 foods to eat organic.
>
> 1N1653A
> [[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() with "Date" class?

2008-05-08 Thread Deepayan Sarkar
On 5/8/08, Ola Caster <[EMAIL PROTECTED]> wrote:
> Dear help list,
>
>  Is it possible to draw lattice histograms (i.e. use the histogram() function
>  and not the hist() function) with objects of class "Date"?

Sort of. The default calculation of 'breaks' doesn't work, so

histogram(~date, data=my.data)

will currently fail (I will fix this in the next update). However,

histogram(~date, data=my.data, breaks = 10)
histogram(~date, data=my.data, breaks = "fd")

etc., should work. The help page for histogram is somewhat ambiguous; it says:

  breaks:

  [...]

  Other valid values
  of 'breaks' are those of the 'breaks' argument in 'hist'.
  This allows specification of 'breaks' as an integer giving
  the number of bins (similar to 'nint'), as a character string
  denoting a method, and as a function.

What is meant here is that valid values of breaks in 'hist.default'
will work, not those for any other methods. In particular, breaks =
"months" will not work.

-Deepayan

>  I've tried solutions like
>
>  histogram(~date, data=my.data, breaks="months")
>
>  but it doesn't seem to work.
>
>  Any suggestions are welcome.
>
>  Many thanks
>  Ola Caster

__
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 "Date" class?

2008-05-08 Thread Ola Caster
Thanks a lot Deepayan. Could you please inform me what update are you
referring to, and give me some very vague sense when it might happen (within
weeks, months, or years)?

Many thanks
Ola

2008/5/8 Deepayan Sarkar <[EMAIL PROTECTED]>:

> On 5/8/08, Ola Caster <[EMAIL PROTECTED]> wrote:
> > Dear help list,
> >
> >  Is it possible to draw lattice histograms (i.e. use the histogram()
> function
> >  and not the hist() function) with objects of class "Date"?
>
> Sort of. The default calculation of 'breaks' doesn't work, so
>
> histogram(~date, data=my.data)
>
> will currently fail (I will fix this in the next update). However,
>
> histogram(~date, data=my.data, breaks = 10)
> histogram(~date, data=my.data, breaks = "fd")
>
> etc., should work. The help page for histogram is somewhat ambiguous; it
> says:
>
>  breaks:
>
>  [...]
>
>  Other valid values
>  of 'breaks' are those of the 'breaks' argument in 'hist'.
>  This allows specification of 'breaks' as an integer giving
>  the number of bins (similar to 'nint'), as a character string
>  denoting a method, and as a function.
>
> What is meant here is that valid values of breaks in 'hist.default'
> will work, not those for any other methods. In particular, breaks =
> "months" will not work.
>
> -Deepayan
>
> >  I've tried solutions like
> >
> >  histogram(~date, data=my.data, breaks="months")
> >
> >  but it doesn't seem to work.
> >
> >  Any suggestions are welcome.
> >
> >  Many thanks
> >  Ola Caster
>

[[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 "Date" class?

2008-05-09 Thread Ola Caster
Sorry for spamming the list...


I noticed that if you first produce a date histogram with the hist()
function, like this:

basic.histogram <- hist(my.data$date, breaks = "months", plot = FALSE)

and then try to transfer the breaks from that histogram to a lattice
equivalent, like this:

histogram(~date, data=my.data, breaks=basic.histogram$breaks)

then I get a histogram that looks exactly like the original one, except the
bins are not placed correctly on the x-axis. In my case they were all
shifted almost a year to the right. Does anyone know why this happened and
if there is a way to deal with it?

Many thanks
Ola




2008/5/9 Ola Caster <[EMAIL PROTECTED]>:

>
>
> Thanks a lot Deepayan. Could you please inform me what update are you
> referring to, and give me some very vague sense when it might happen (within
> weeks, months, or years)?
>
> Many thanks
> Ola
>
> 2008/5/8 Deepayan Sarkar <[EMAIL PROTECTED]>:
>
>  On 5/8/08, Ola Caster <[EMAIL PROTECTED]> wrote:
>> > Dear help list,
>> >
>> >  Is it possible to draw lattice histograms (i.e. use the histogram()
>> function
>> >  and not the hist() function) with objects of class "Date"?
>>
>> Sort of. The default calculation of 'breaks' doesn't work, so
>>
>> histogram(~date, data=my.data)
>>
>> will currently fail (I will fix this in the next update). However,
>>
>> histogram(~date, data=my.data, breaks = 10)
>> histogram(~date, data=my.data, breaks = "fd")
>>
>> etc., should work. The help page for histogram is somewhat ambiguous; it
>> says:
>>
>>  breaks:
>>
>>  [...]
>>
>>  Other valid values
>>  of 'breaks' are those of the 'breaks' argument in 'hist'.
>>  This allows specification of 'breaks' as an integer giving
>>  the number of bins (similar to 'nint'), as a character string
>>  denoting a method, and as a function.
>>
>> What is meant here is that valid values of breaks in 'hist.default'
>> will work, not those for any other methods. In particular, breaks =
>> "months" will not work.
>>
>> -Deepayan
>>
>> >  I've tried solutions like
>> >
>> >  histogram(~date, data=my.data, breaks="months")
>> >
>> >  but it doesn't seem to work.
>> >
>> >  Any suggestions are welcome.
>> >
>> >  Many thanks
>> >  Ola Caster
>>
>
>

[[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 "Date" class?

2008-05-09 Thread Deepayan Sarkar
On 5/9/08, Ola Caster <[EMAIL PROTECTED]> wrote:
>
> Sorry for spamming the list...
>
>
> I noticed that if you first produce a date histogram with the hist()
> function, like this:
>
> basic.histogram <- hist(my.data$date, breaks = "months", plot = FALSE)
>
> and then try to transfer the breaks from that histogram to a lattice
> equivalent, like this:
>
> histogram(~date, data=my.data, breaks=basic.histogram$breaks)
>
> then I get a histogram that looks exactly like the original one, except the
> bins are not placed correctly on the x-axis. In my case they were all
> shifted almost a year to the right. Does anyone know why this happened and
> if there is a way to deal with it?

I can't comment on what you see unless you give us a reproducible
example, but I only see a shift in the label positions (so the labels
are different, but still accurate in both cases). For example,

foo <- Sys.Date() + 10 * rnorm(100)
bar <- hist(foo, breaks = "months")
dev.new()
histogram(~foo, breaks = bar$breaks,
  scales = list(x = list(format = "%b %d")))

-Deepayan

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


Re: [R] Histogram/Bar plot graph

2008-02-06 Thread ONKELINX, Thierry
You'll need to transform your dataset in a long format first.

library(ggplot2)
n <- 5
MyValues <- data.frame(Gene = factor(LETTERS[seq_len(n)]), ES =
rnorm(n), MEF = rnorm(n), Embrio = rnorm(n), EShyp = rnorm(n))
MyValuesMelt <- melt(MyValues, id.var = "Gene")
ggplot(MyValuesMelt, aes(x = Gene, y = value, fill = variable)) +
geom_bar(position = "dodge") 
ggplot(MyValuesMelt, aes(x = Gene, y = value)) + geom_bar(position =
"dodge") + facet_grid(. ~ variable)

HTH,

Thierry


ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium 
tel. + 32 54/436 185
[EMAIL PROTECTED] 
www.inbo.be 

Do not put your faith in what statistics say until you have carefully
considered what they do not say.  ~William W. Watt
A statistical analysis, properly conducted, is a delicate dissection of
uncertainties, a surgery of suppositions. ~M.J.Moroney

-Oorspronkelijk bericht-
Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Namens Senthil Kumar M
Verzonden: woensdag 6 februari 2008 11:19
Aan: r-help@r-project.org
Onderwerp: [R] Histogram/Bar plot graph

Hi,

I have the following data:

> Myvalues
 Gene  ES   MEF Embryo  ESHyp
1   GeneA   -0.38509507  0.00 1.6250  1.7039921
2   GeneB0.06262914  0.00 1.6250 -0.272033
and so on...

I want to plot the expression values of GeneA and GeneB in the different
cell/embryo/conditions (columns 2:5 above). Now, if I do:

>library(ggplot2)
> qplot(x=Gene, Embryo, geom = "bar")

I get a plot of GeneA, B...so on only for the Embryo (ie column 4).

How do I get to plot multiple instances of Y for the same value of X ?

I have tried to find this out myself, but it is a bit confusing and so,
I am writing to the list as a last resort.

Any help or guidance will be much appreciated.

TIA,

Senthil

__
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/Bar plot graph

2008-02-06 Thread Senthil Kumar M
On Feb 6, 2008 2:35 AM, ONKELINX, Thierry <[EMAIL PROTECTED]> wrote:
> You'll need to transform your dataset in a long format first.
>
> library(ggplot2)
> n <- 5
> MyValues <- data.frame(Gene = factor(LETTERS[seq_len(n)]), ES =
> rnorm(n), MEF = rnorm(n), Embrio = rnorm(n), EShyp = rnorm(n))
> MyValuesMelt <- melt(MyValues, id.var = "Gene")
> ggplot(MyValuesMelt, aes(x = Gene, y = value, fill = variable)) +
> geom_bar(position = "dodge")
> ggplot(MyValuesMelt, aes(x = Gene, y = value)) + geom_bar(position =
> "dodge") + facet_grid(. ~ variable)
>

Hi Thierry,
Splendid! It is exactly what I wanted.
Now, I am actually studying your reply to understand what those
commands *actually* do.

Thanks a lot,
Sincerely Yours,
Senthil

__
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 for integer data

2008-03-27 Thread Don MacQueen
You might consider something based on the concept of:

   y <- table( x)
   plot( as.numeric(names(y)) , y, type='h')

-Don

At 2:59 PM -0400 3/27/08, <[EMAIL PROTECTED]> wrote:
>hi,
>
>library(lattice)
>x<-c(-1,-1,-1,0,0,0,0,1,1,2)
>rng<-range(x)
>histogram(x,endpoints=c(rng[1]-0.5,rng[2]+0.5),nint=length(unique(x)))
>
>instead of contiguous bins, i'd like spaces between them to indicate
>that the data is discrete, or even better, line segments positioned at
>integer values.
>i know how to do this with plot, but i need it with histogram, so that
>in more complicated contexts i can use histogram(~x| f1 * f2)
>
>thanks!
>
>
>
>   [[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.


-- 
--
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
925-423-1062

__
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 for integer data

2008-03-27 Thread Erwann.Rogard
Thanks!

Yes, but I also want to be able to condition easily hence
histogram(...), not plot


-Original Message-
From: Don MacQueen [mailto:[EMAIL PROTECTED] 
Sent: Thursday, March 27, 2008 3:55 PM
To: Rogard, Erwann R&D/US/EXT; r-help@r-project.org
Subject: Re: [R] histogram for integer data

You might consider something based on the concept of:

   y <- table( x)
   plot( as.numeric(names(y)) , y, type='h')

-Don

At 2:59 PM -0400 3/27/08, <[EMAIL PROTECTED]> wrote:
>hi,
>
>library(lattice)
>x<-c(-1,-1,-1,0,0,0,0,1,1,2)
>rng<-range(x)
>histogram(x,endpoints=c(rng[1]-0.5,rng[2]+0.5),nint=length(unique(x)))
>
>instead of contiguous bins, i'd like spaces between them to indicate 
>that the data is discrete, or even better, line segments positioned at 
>integer values.
>i know how to do this with plot, but i need it with histogram, so that 
>in more complicated contexts i can use histogram(~x| f1 * f2)
>
>thanks!
>
>
>
>   [[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.


--
--
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
925-423-1062

__
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 as step function

2007-11-15 Thread Hakim Tafer
Hi

I want to plot a histogram (not cumulative!) as a step-function.
Any idea how achieve this?

Thank you

__
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 and moving average

2009-04-14 Thread Dieter Menne
Vallat Morgan  epfl.ch> writes:

> I have a 'basic' issue and hope someone has a bit of code to solve it. I
> have two populations plotted as histograms on the same figure. Basically I
want to add the moving average
> (based on hist) for both populations on my graph. I'm also interested in the x
coordinate of the curves
> intersection. 

Moving averages are fine if you do not have future data (such as stock markets
or temperatures), but suboptimal for densities.

R has powerful methods for these: If you have MASS (the book, check ch. 5.6). Or
the examples in library/MASS/scripts/ch05.R

Dieter

__
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 inset into another histogram

2008-06-19 Thread Paul Hiemstra

Victor Homar wrote:

Dear R users and helpers,

I'm trying to find an example of a histogram plot as an inset (upper 
right or left corner) of another histogram.


Anyone has an example of that?

Thanks for your help,

Víctor.


Hi,

You can use the histogram function from the lattice package (standard in 
R) in combination with the print statement. Example:


library(lattice)
h = histogram(cars$speed)
h2 = histogram(cars$speed, xlab = "", ylab="")
print(h, more = T)
print(h2, position = c(.05,.65,.5,.95))

The position argument in print gives the bounding box for the lattice 
object. The coordinate system is c(x1,y1,x2,y2) where (x1,y1) is the 
bottom left corner and (x2,y2) is the top right corner. The coordinate 
system runs from (0,0) in the bottom left corner to (1,1) in the top 
right corner.


hth and cheers,
Paul

--
Drs. Paul Hiemstra
Department of Physical Geography
Faculty of Geosciences
University of Utrecht
Heidelberglaan 2
P.O. Box 80.115
3508 TC Utrecht
Phone:  +31302535773
Fax:+31302531145
http://intamap.geo.uu.nl/~paul

__
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 inset into another histogram

2008-06-19 Thread Victor Homar

Hi Paul,

Thanks for the answer. I temporarily did it with the subplot function 
from the TeachingDemos package but I like this version much better.


Best,
Victor.

Paul Hiemstra wrote:

Victor Homar wrote:

Dear R users and helpers,

I'm trying to find an example of a histogram plot as an inset (upper 
right or left corner) of another histogram.


Anyone has an example of that?

Thanks for your help,

Víctor.


Hi,

You can use the histogram function from the lattice package (standard 
in R) in combination with the print statement. Example:


library(lattice)
h = histogram(cars$speed)
h2 = histogram(cars$speed, xlab = "", ylab="")
print(h, more = T)
print(h2, position = c(.05,.65,.5,.95))

The position argument in print gives the bounding box for the lattice 
object. The coordinate system is c(x1,y1,x2,y2) where (x1,y1) is the 
bottom left corner and (x2,y2) is the top right corner. The coordinate 
system runs from (0,0) in the bottom left corner to (1,1) in the top 
right corner.


hth and cheers,
Paul

--
---
Víctor Homar Santaner
Grup de Meteorologia

Edif. Mateu Orfila  Tel: +34 971 17 1376
Universitat de les Illes BalearsFax: +34 971 17 3426
07122 Palma de Mallorca (SPAIN) Email: [EMAIL PROTECTED]

 Knowledge is contagious. Infect truth.

__
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 colors according to factor

2008-07-08 Thread Hans W. Borchers

Given a data frame with a continuous variable and a factor. I would like to
generate a histogram of the continuous variable, where each bar is filled
with different colors according to the percentage of factor values falling
into this region of the continuous variable.

I looked into packages like 'lattice' and 'ggplot2'. Searching R-help
revealed that 'histogram' is spelled 'histogramm' in almost 2% of the
time.  I now know how to color whole bars, but did not find a solution
for this specific kind of visualization.

Many thanks in advance,  Hans Werner Borchers


Hans W. Borchers
ABB Corporate Research

-

Hans W. Borchers
ABB Corporate Research Germany
-- 
View this message in context: 
http://www.nabble.com/Histogram-with-colors-according-to-factor-tp18336930p18336930.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 - freq=FALSE - density computation

2008-08-07 Thread Duncan Murdoch

On 07/08/2008 6:55 PM, Jörg Groß wrote:

Hi,

I don't understand what

hist(x, freq=FALSE)

does.


At first I thought it would be just the relative frequencies instead  
of the absolute frequencies,

by just computing "frequencies / n" in every category.

But with a small dataset the y-values (densities) don't sum to one.

Is there a way to get the histogram doing that?
Or what is the idea of this density-computation?


I hope the question is not too stupid...


It returns a probability density function, so the result integrates to 
one.  If the bars are chosen at unit spacings it will sum to one.


Duncan Murdoch

__
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-like plot with two variables

2008-09-28 Thread Jörg Groß
Hi,

I want to plot a binomial propability distribution.

I know how to generate the data;

   x <- seq(from=0, to=14, by=1)
   y <- dbinom(x, 14, 0.7, log = FALSE)

but what I don't know is how to plot this within a histogram like plot.
Because the histogram function only accepts one variable.

Is there a way to get the look of "hist()" with two variables?



I tried:
plot(x,y, type="h")
  but the bars are very thin -is there a way to define the width?



[[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 for grouped data in R

2009-01-23 Thread darthgervais

I have grouped data in this format

Size  -- Count
0-10 --  15
10-20 -- 25
20-50 -- 10
50-100 -- 5

I've been trying to find a way to set this up with the proper histogram
heights, but can't seem to figure it out. So any help would be much
appreciated!
-- 
View this message in context: 
http://www.nabble.com/Histogram-for-grouped-data-in-R-tp21624806p21624806.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 in Lattice with 3 factors

2008-02-11 Thread willem vervoort
Dear R-help list,

I am trying to construct a lattice histogram using 3 factors.

My dataframe looks like this: (simulating a waterbalance over
groundwater with different salinities)

s  days   modelECEC_max
0.4 1"A"   10  9
0.42   2"A"   10  9
0.44   3"A"   10   9
  ::  :   : :
0.4  1"B"  10  9
  ::  :  : :
0.4  1"A"  309
  ::  :  :   :
0.4  1"A"  3036

Anyway you get the gist
EC_max has two levels 9 and 36, EC has 3 levels 10, 30 and 70, and
model has two levels ("A" and "B"). There are say 365 days and s is
the variable of interest (soil saturation)

Can maybe be reproduced with:
data <- data.frame(s = rnorm(2*3*365*2),rep(1:365,12), model =
sort(rep(c("A","B"),6*365)),
EC = rep(sort(rep(c(10,30,70),365*2)),2), EC_max =
rep(sort(rep(c(9,36),3*365)),2))

I would like to plot histograms with the three factors using Lattice
so I had the following code:

my.strip <- function(which.given, ..., factor.levels) {
levs <- if (which.given == 1)  c("Model A","Model B")
else {if(which.given == 2) paste("EC =
",as.character(EC),"dS/m")
  else paste("ECmax = ",as.character(EC_max),"dS/m")}
strip.default(which.given, ..., factor.levels = levs)
 }

histogram(~s|model*as.factor(EC)*as.factor(EC_max),data=Store,xlab="soil
saturation",type="density",strip=my.strip)

But I am doing something wrong, because it plots the histogram for
factor level EC_max =9 first and than straight over it the histogram
for factor level 36, so only 6 panels on the graph rather than 12.

I searched the archives, but no luck so far.

Any help is appreciated

Willem

platform   i386-pc-mingw32
arch   i386
os mingw32
system i386, mingw32
status
major  2
minor  6.1
year   2007
month  11
day26
svn rev43537
language   R
version.string R version 2.6.1 (2007-11-26)

__
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 like x labels in barplot

2008-03-06 Thread Hyunchul Kim
Hi, all

I drew a barplot with

> barplot(data1, beside=TRUE)

and then, I want to labels with hist() like x-axis ticks.

How can I do this?

Thanks in advance,
Hyunchul

__
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 as step function

2007-11-15 Thread David Scott
On Thu, 15 Nov 2007, Hakim Tafer wrote:

> Hi
>
> I want to plot a histogram (not cumulative!) as a step-function.
> Any idea how achieve this?
>
> Thank you
>

Well if I understand you correctly you can do this.

x<-rnorm(100)
par(mfrow=c(2,1))
hist(x)
histRes <- hist(x,plot=FALSE)
xvals <- histRes$breaks
yvals <- histRes$counts
length(xvals)
length(yvals)
xvals <- c(xvals,xvals[length(xvals)])
yvals <- c(0,yvals,0)
plot(xvals,yvals,type="S")

David Scott
_
David Scott Department of Statistics, Tamaki Campus
The University of Auckland, PB 92019
Auckland 1142,NEW ZEALAND
Phone: +64 9 373 7599 ext 86830 Fax: +64 9 373 7000
Email:  [EMAIL PROTECTED]

Graduate Officer, Department of Statistics
Director of Consulting, Department of Statistics

__
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 plots with many different samples

2009-03-25 Thread evrim akar
Dear R users,

I would like to draw some histograms as seen in the page whose address I
wrote below. I searched through the web a lot and I found a page which
describes how I can do it for older versions of R. For newer versions they
recommend to install the package R.basics in R.clusters but this does not
exist. The address of the web page is
http://www1.maths.lth.se/help/R/plot.histogram/

Unfortunately I could not find any other resource or help. Is it possible to
make histograms like I wanted with R? If so, could you please give any
advise on how I can do it?

Thank you,

Regards,

evrim

[[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 for time with format hh:mm

2009-06-17 Thread Shreyasee
Hi,

I have a dataset and calculated the time difference between two time
variables.
The output is somewhat like *"1/29/2324  1:57:39 AM".*
I want to plot a histogram for this variable. When I gave *hist()* command
it returned an error saying *"Error in hist.default(num) : 'x' must be
numeric"*
Can anybody guide me on this as to how should I plot the histogram for this?


Thanks,
Shreyasee

[[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 colors according to factor

2008-07-08 Thread ONKELINX, Thierry
Is this what you want?

dataset <- data.frame(x = c(rnorm(100), runif(100), rchisq(100, 1)), y =
gl(3, 100, labels = LETTERS[1:3]))
ggplot(dataset, aes(x = x, fill = y)) + geom_histogram()
ggplot(dataset, aes(x = x, fill = y)) + geom_histogram(position =
"dodge")

HTH,

Thierry 




ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium 
tel. + 32 54/436 185
[EMAIL PROTECTED] 
www.inbo.be 

To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to
say what the experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of
data.
~ John Tukey

-Oorspronkelijk bericht-
Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Namens Hans W. Borchers
Verzonden: dinsdag 8 juli 2008 13:23
Aan: r-help@r-project.org
Onderwerp: [R] Histogram with colors according to factor


Given a data frame with a continuous variable and a factor. I would like
to
generate a histogram of the continuous variable, where each bar is
filled
with different colors according to the percentage of factor values
falling
into this region of the continuous variable.

I looked into packages like 'lattice' and 'ggplot2'. Searching R-help
revealed that 'histogram' is spelled 'histogramm' in almost 2% of the
time.  I now know how to color whole bars, but did not find a solution
for this specific kind of visualization.

Many thanks in advance,  Hans Werner Borchers


Hans W. Borchers
ABB Corporate Research

-

Hans W. Borchers
ABB Corporate Research Germany
-- 
View this message in context:
http://www.nabble.com/Histogram-with-colors-according-to-factor-tp183369
30p18336930.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 with colors according to factor

2008-07-08 Thread Hans W. Borchers

No; thanks for your try, but this is not what I want.

Here each bar has one single color. I would like to render each bar with
several colors according to the distribution of a factor.

I now learned that this is called "stacked histogram" (damned Excel).  In
the following entry

https://stat.ethz.ch/pipermail/r-help/2007-April/129645.html

Deepayan Sarkar has provided a solution though he doubts its value. Still, I
find "stacked histograms" a vuable tool during exploratory data analysis. 

Hans Werner


Is this what you want?

dataset <- data.frame(x = c(rnorm(100), runif(100), rchisq(100, 1)), y =
gl(3, 100, labels = LETTERS[1:3]))
ggplot(dataset, aes(x = x, fill = y)) + geom_histogram()
ggplot(dataset, aes(x = x, fill = y)) + geom_histogram(position =
"dodge")

HTH,

Thierry 


-

Hans W. Borchers
ABB Corporate Research Germany
-- 
View this message in context: 
http://www.nabble.com/Histogram-with-colors-according-to-factor-tp18336930p18337935.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 with colors according to factor

2008-07-08 Thread ONKELINX, Thierry
After reading your question again I came up with these plots.

dataset <- data.frame(x = c(rnorm(1000), rnorm(200, mean = 1)), y =
gl(2, 100, labels = LETTERS[1:2]))
ggplot(dataset, aes(x = x, group = y)) + stat_bin(aes(fill = ..count..),
width = 0.2) + scale_fill_gradient(low = "red", high = "green")
ggplot(dataset, aes(x = x)) + stat_bin(aes(fill = ..ncount..), width =
0.2) + scale_fill_gradient(low = "red", high = "green") + facet_grid(. ~
y)
ggplot(dataset, aes(x = x)) + stat_bin(aes(fill = ..count..), width =
0.2) + scale_fill_gradient(low = "red", high = "green") + facet_grid(. ~
y)

HTH,

Thierry 




ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium 
tel. + 32 54/436 185
[EMAIL PROTECTED] 
www.inbo.be 

To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to
say what the experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of
data.
~ John Tukey

-Oorspronkelijk bericht-
Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Namens Hans W. Borchers
Verzonden: dinsdag 8 juli 2008 14:23
Aan: r-help@r-project.org
Onderwerp: Re: [R] Histogram with colors according to factor


No; thanks for your try, but this is not what I want.

Here each bar has one single color. I would like to render each bar with
several colors according to the distribution of a factor.

I now learned that this is called "stacked histogram" (damned Excel).
In
the following entry

https://stat.ethz.ch/pipermail/r-help/2007-April/129645.html

Deepayan Sarkar has provided a solution though he doubts its value.
Still, I
find "stacked histograms" a vuable tool during exploratory data
analysis. 

Hans Werner


Is this what you want?

dataset <- data.frame(x = c(rnorm(100), runif(100), rchisq(100, 1)), y =
gl(3, 100, labels = LETTERS[1:3]))
ggplot(dataset, aes(x = x, fill = y)) + geom_histogram()
ggplot(dataset, aes(x = x, fill = y)) + geom_histogram(position =
"dodge")

HTH,

Thierry 


-

Hans W. Borchers
ABB Corporate Research Germany
-- 
View this message in context:
http://www.nabble.com/Histogram-with-colors-according-to-factor-tp183369
30p18337935.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 with colors according to factor

2008-07-08 Thread hadley wickham
> Given a data frame with a continuous variable and a factor. I would like to
> generate a histogram of the continuous variable, where each bar is filled
> with different colors according to the percentage of factor values falling
> into this region of the continuous variable.

How exactly do you want the bar coloured?  I can see that this might
possibly work if the factor has only two levels, but how is a colour
supposed to encode the a categorical distribution?

Or do you mean:

dataset <- data.frame(x = c(rnorm(100), runif(100), rchisq(100, 1)), y =
gl(3, 100, labels = LETTERS[1:3]))
ggplot(dataset, aes(x = x, fill = y)) + geom_histogram(position = "fill")


Hadley


-- 
http://had.co.nz/

__
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 two colors depending on condition

2008-07-17 Thread Mohammad Ehsanul Karim
Dear List,

Say, we generate data like this-

dat<-rnorm(1000,1,2)
hist(dat)

How do i make the histogram, say, red (col = 2) before X = dat = 0, and rest 
say, green (col = 3) beyond X = dat = 0 in R? 

The resulting histogram could be like this 
http://ehsan.karim.googlepages.com/histogram.JPG (edited)

Thanks in advance.

Ehsan
http://ehsan.karim.googlepages.com/diaryofastatistician

__
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-like plot with two variables

2008-09-28 Thread jim holtman
Try:

plot(x,y,type='s')
lines(x,y, type='h')

On Sun, Sep 28, 2008 at 10:02 PM, Jörg Groß <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I want to plot a binomial propability distribution.
>
> I know how to generate the data;
>
>   x <- seq(from=0, to=14, by=1)
>   y <- dbinom(x, 14, 0.7, log = FALSE)
>
> but what I don't know is how to plot this within a histogram like plot.
> Because the histogram function only accepts one variable.
>
> Is there a way to get the look of "hist()" with two variables?
>
>
>
> I tried:
> plot(x,y, type="h")
>  but the bars are very thin -is there a way to define the width?
>
>
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



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

What is the problem that you are trying to solve?

__
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-like plot with two variables

2008-09-29 Thread Duncan Murdoch

On 28/09/2008 10:02 PM, Jörg Groß wrote:

Hi,

I want to plot a binomial propability distribution.

I know how to generate the data;

   x <- seq(from=0, to=14, by=1)
   y <- dbinom(x, 14, 0.7, log = FALSE)

but what I don't know is how to plot this within a histogram like plot.
Because the histogram function only accepts one variable.

Is there a way to get the look of "hist()" with two variables?



I tried:
plot(x,y, type="h")
  but the bars are very thin -is there a way to define the width?


You could use barplot():

barplot(y,names=x)

You could also do it with plot.histogram, but it's trickier, because 
it's designed for continuous data.  For example,


dat <- hist(x, plot=FALSE, breaks=c(-1,x)+0.5)
dat$density <- y
plot(dat, freq=FALSE)

Duncan Murdoch

__
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-like plot with two variables

2008-09-29 Thread Jim Lemon

Jörg Groß wrote:

Hi,

I want to plot a binomial propability distribution.

I know how to generate the data;

   x <- seq(from=0, to=14, by=1)
   y <- dbinom(x, 14, 0.7, log = FALSE)

but what I don't know is how to plot this within a histogram like plot.
Because the histogram function only accepts one variable.

Is there a way to get the look of "hist()" with two variables?



I tried:
plot(x,y, type="h")
  but the bars are very thin -is there a way to define the width?


  

Hi Jorg,
Does this do what you want?

library(plotrix)
barp(y,names.arg=0:14)


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-like plot with two variables

2008-09-29 Thread Philipp Pagel
On Mon, Sep 29, 2008 at 04:02:05AM +0200, Jörg Groß wrote:
> Hi,
> 
> I want to plot a binomial propability distribution.
> 
> I know how to generate the data;
> 
>x <- seq(from=0, to=14, by=1)
>y <- dbinom(x, 14, 0.7, log = FALSE)
> 
> I tried:
> plot(x,y, type="h")
>   but the bars are very thin -is there a way to define the width?

yes - the lwd parameter controls line width. E.g.:

plot(x,y, type='h', lwd=5)

This is the way I usually plot count data - I prefer this over something
that looks like a normal histogram, because it reminds me that I am
looking at discrete values.

cu
Philipp

-- 
Dr. Philipp Pagel
Lehrstuhl für Genomorientierte Bioinformatik
Technische Universität München
Wissenschaftszentrum Weihenstephan
85350 Freising, Germany
http://mips.gsf.de/staff/pagel

__
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-like plot with two variables

2008-09-29 Thread Greg Snow
An added note, if you use this approach, then you should probably set the lend 
parameter as well (becomes more important with wider lines).  See ?par and 
scroll down to lend for options/details.

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[EMAIL PROTECTED]
801.408.8111


> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> project.org] On Behalf Of Philipp Pagel
> Sent: Monday, September 29, 2008 5:40 AM
> To: r-help@r-project.org
> Subject: Re: [R] histogram-like plot with two variables
>
> On Mon, Sep 29, 2008 at 04:02:05AM +0200, Jörg Groß wrote:
> > Hi,
> >
> > I want to plot a binomial propability distribution.
> >
> > I know how to generate the data;
> >
> >x <- seq(from=0, to=14, by=1)
> >y <- dbinom(x, 14, 0.7, log = FALSE)
> >
> > I tried:
> > plot(x,y, type="h")
> >   but the bars are very thin -is there a way to define the width?
>
> yes - the lwd parameter controls line width. E.g.:
>
> plot(x,y, type='h', lwd=5)
>
> This is the way I usually plot count data - I prefer this over
> something
> that looks like a normal histogram, because it reminds me that I am
> looking at discrete values.
>
> cu
> Philipp
>
> --
> Dr. Philipp Pagel
> Lehrstuhl für Genomorientierte Bioinformatik
> Technische Universität München
> Wissenschaftszentrum Weihenstephan
> 85350 Freising, Germany
> http://mips.gsf.de/staff/pagel
>
> __
> 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 with different colors for different portions

2007-12-30 Thread arnholtat
Dear Rusers,
I would like to color different sections of a histogram different colors.
I have an example that was done by "brute force" given below.  Has anyone
implemented something like this in general?  If not, any suggestions/pointers
on how to write a general function to do so would be most appreciated.
Alan-

set.seed(13)
nnum <- rnorm(1000, 100, 10)
xbar <- mean(nnum)
SD <- sd(nnum)
BR <- seq(xbar - 4*SD, xbar + 4*SD, by = .25*SD)
# Histogram showing xbar +- sd in different colors
hist(nnum, breaks=BR, col=c(rep("red", 8), rep("blue", 4),
 rep("pink", 8), rep("blue", 4), rep("red", 8)))

# Histogram depicting Hinge Spread with boxplot
layout(matrix(c(1, 2)), heights=c(2, 1))
fn <- fivenum(nnum)
LH <- fn[2]
UH <- fn[4]
HS <- UH - LH
SHS <- HS/10
BR <- seq(LH - SHS*30, UH + SHS*30, SHS)
par(mar=c(0,2,3,2))
hist(nnum, breaks=BR, col=c(rep("red", 30), rep("blue", 10),
 rep("red", 30)), xlim=c(60,140), axes=FALSE, xlab="",
 ylab="", main="")
#
par(mar=c(3,2,0,2))
boxplot(nnum, col="blue", horizontal=TRUE, ylim=c(60, 140), axes=FALSE)
axis(side=1)

Alan T. Arnholt 
Professor and Assistant Chair 
Department of Mathematical Sciences 
Appalachian State University 
T:(828)262-2863 
F:(828)265-8617 
http://www1.appstate.edu/~arnholta/ 
__
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 for grouped data in R

2009-01-23 Thread Vincent Goulet

Le ven. 23 janv. à 08:55, darthgervais a écrit :



I have grouped data in this format

Size  -- Count
0-10 --  15
10-20 -- 25
20-50 -- 10
50-100 -- 5

I've been trying to find a way to set this up with the proper  
histogram

heights, but can't seem to figure it out. So any help would be much
appreciated!


Define your data as a "grouped.data" object using the function of the  
same name in package actuar. Then you can simply use hist() as usual  
to get what you want. See:


@Article{Rnews:Goulet+Pigeon:2008,
 author = {Vincent Goulet and Mathieu Pigeon},
 title = {Statistical Modeling of Loss Distributions Using actuar},
 journal = {R News},
 year = 2008,
 volume = 8,
 number = 1,
 pages = {34--40},
 month = {May},
 url = http, pdf = Rnews2008-1 }

HTH

---
  Vincent Goulet
  Acting Chair, Associate Professor
  École d'actuariat
  Université Laval, Québec
  vincent.gou...@act.ulaval.ca   http://vgoulet.act.ulaval.ca

__
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 for grouped data in R

2009-01-23 Thread Jorge Ivan Velez
Hi,
Try this:

x<-c(15,25,10,5)
names(x)<-c('0-10','10-20','20-50','50-100')
barplot(x,space=0,xlab='Size',ylab='Count',col=1:4)

See ?barplot for more information.

HTH,

Jorge



On Fri, Jan 23, 2009 at 8:55 AM, darthgervais  wrote:

>
> I have grouped data in this format
>
> Size  -- Count
> 0-10 --  15
> 10-20 -- 25
> 20-50 -- 10
> 50-100 -- 5
>
> I've been trying to find a way to set this up with the proper histogram
> heights, but can't seem to figure it out. So any help would be much
> appreciated!
> --
> View this message in context:
> http://www.nabble.com/Histogram-for-grouped-data-in-R-tp21624806p21624806.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.
>

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


  1   2   >