[R] Plotting and quantiles

Mark D. d.mark55 at ymail.com
Sun Aug 14 15:45:46 CEST 2011


Thanks very much. The cut function is exactly what I was looking for. For the graph I forgot to include an example (picture attached). I think it is something different from what you have shown in the examples. I want to plot all the data in a line plot - exactly how it is shown in the attached graph.


Mark




________________________________
From: R. Michael Weylandt <michael.weylandt at gmail.com>
To: Mark D. <d.mark55 at ymail.com>
Cc: "r-help at r-project.org" <r-help at r-project.org>
Sent: Saturday, 13 August 2011, 21:39
Subject: Re: [R] Plotting and quantiles


I believe you received an informative answer to both these questions from Daniel Maiter one hour and twenty five minutes after sending your question: I repeat it here just in case you didn't get it. 

--------------------------

Q1 is very opaque because you are not even saying what kind of plot you want.
For a regular scatterplot, you have multiple options.

a.) select only the data in the given intervals and plot the data

b.) plot the entire data, but restrict the graph region to the intervals you
are interested in, or

c.) winsorize the data (i.e., set values below the lower cutoff and above
the upper cutoff to the cutoff values

Which one you want to do depends on which one makes the most sense given the
purpose of your analysis

Say:

x<-rnorm(100)
y<-x+rnorm(100)

Then

a.) plot(y~x,data=data.frame(x,y)[
x<2&x>-2 , ])
#plots y against x only for xs between -2 and 2

b.) plot(y~x,xlim=c(-2,2))

#plots all y agains x, but restricts the plotting region to -2 to 2 on the
x-axis

c.)

x<-replace(x,x>2,2)
x<-replace(x,x<(-2),-2)
plot(y~x)

#sets all x-values below -2 and above 2 to these cutoffs



Q2: look at the cut() function.

?cut

HTH,
Daniel

---------------------

If you need more information, a different solution, or further clarification, please ask new questions. 

Michael Weylandt


On Sat, Aug 13, 2011 at 10:10 AM, Mark D. <d.mark55 at ymail.com> wrote:

Dear R users,
>
>
>This is most likely very basic question but I am new to R and would really appreciate some tips on those two problems.
>
>1) I need to plot variables from a data frame. Because of some few high numbers my graph is really strange looking. How could I plot a fraction of the samples (like 0.1 (10%), 0.2 up to for example 0.6) on x axis and values 'boundaries' (like any value '< 100',  '101-200' and '> 201') on the y axis? This needs to be a simple line plot like the one I attached for an example. The values would come from one column.
>
>
>2) I have a data frame with values and need to subset the rows based on the values. I wanted to order them (with increasing values) and divide into 3-4 groups. I though about using quantile but I want the group to be something like '1-25', '26-50', '51-75', '75-100' (ordered and for example 25th percentile, 26-50th etc). I could just look for a median divide into two and then again (or use quantiles 0.25, 0.5, 0.7 and 1 and then get rid of all rows in 0.25 that are in 0.5 etc) but surely there must by a faster and simpler way to do that (I need to do this a lot on different columns)?
>
>Thanks for your help,
>Mark
>______________________________________________
>R-help at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: viewer.png
Type: image/png
Size: 6799 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110814/6abe189e/attachment.png>


More information about the R-help mailing list