[R] plotting segments only and in color

Dennis Murphy djmuser at gmail.com
Mon Aug 15 23:33:29 CEST 2011


Hi:

Here's one approach using the ggplot2 package:

Y=c(15,14,23,18,19,9,19,13)
Xa=c(17,22,21,18,19,25,8,19)
Xb=c(22,22,29,34,19,26,17,22)

dd <- data.frame(Y, Xa, Xb)
ggplot(dd) +
   geom_segment(aes(x = Xa, xend = Xb, y = Y, yend = Y,
                    colour = Xb - Xa), size = 2) +
   geom_point(aes(x = (Xa + Xb)/2, y = Y), colour = 'red', size = 3) +
   scale_colour_gradientn(limits = c(0, 20), colours = c('gray10',
                           'gray30', 'gray50', 'gray80')) +
   labs(x = 'X', colour = 'X range')

HTH,
Dennis

On Mon, Aug 15, 2011 at 9:01 AM, Johannes Radinger <JRadinger at gmx.at> wrote:
> Hello,
>
> I've a question concerning the display of interval data.
>
> A sample dataset where X is an interval between Xa and Xb
> which should be displayed:
>
> Y=c(15,14,23,18,19,9,19,13)
> Xa=c(17,22,21,18,19,25,8,19)
> Xb=c(22,22,29,34,19,26,17,22)
> X = (Xa+Xb)/2
>
>
> It's easily possible to plot the mean of the interval like:
> plot(X,Y)
>
> afterwards I can create lines for the interval with:
> segments(Xa,Y,Xb,Y)
>
> I think that explains roughly what I'd like to do.
>
> Now some questions:
>
> 1) How can I display the segments only? without the points?
>
> 2) I'd like only to have points where the range (Xa-Xb) = 0, because
> otherwise nothing would be displayed in such cases.
>
> 3) How can I color (grey scale) the interval-segments according to their range?
> Lets say the wider the range (Xa-Xb) the brighter (the more white)and the narrower the darker (more black)?
>
> 4) Is there a special R-package or function besides for plotting interval, or ranging data?
>
> Thanks
>
> /johannes
>
>
>
> --
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list