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 --
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. >
Hi Johannes, plot(X,Y,type="n") creates an empty plot with correct dimensions, ind<-!(Xb==Xa) points(X[ind],Y[ind]) plots points for zero-length intervals only, and gray() can be used for shading lines, as in segments(Xa,Y,Xb,Y,col=gray(.9*(Xb-Xa)/max(Xb-Xa))) #the longest interval will be gray(.9) so it is just visible hth. Am 15.08.2011 18:01, schrieb Johannes Radinger:> 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.-- Eik Vettorazzi Institut f?r Medizinische Biometrie und Epidemiologie Universit?tsklinikum Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/7410-58243 F ++49/40/7410-57790