Re: [R] adding vertical segments to an xyplot in lattice

From: Tóth Dénes <tdenes_at_cogpsyphy.hu>
Date: Wed, 23 Mar 2011 01:07:34 +0100 (CET)

You might also consider the Deducer package. You can build up a plot by point and click and then have a look at (and amend) the code and learn the syntax of ggplot2, which is a nice alternative to the lattice package. The website of the Deducer package (www.deducer.org) is a good start.



Anyway:

mydata <- data.frame(county=factor(1:3),lowlim=c(3,6,4),uplim=c(4,7,6))

In Deducer choose:
Plots / Plot Builder ... Geometric elements / linerange

After running it, you get:
dev.new()
ggplot() +
  geom_linerange(aes(x = county,ymin = lowlim,ymax = uplim),data=mydata)

The same in pure R:
library(ggplot2)
ggplot(data=mydata) +
  geom_linerange(aes(x = county,ymin = lowlim,ymax = uplim))

HTH,
  Denes

> Well, a custom panel function is what you need (or one that may
> already exist somewhere: try googling on "high low intervals in R
> graphs" or some such).
>
> So if you haven;t already done so, try Paul Morrell's Chapter on
> lattice plots from his book for how panel functions work:
>
> http://www.stat.auckland.ac.nz/~paul/RGraphics/chapter4.pdf
>
> -- Bert
>
>
> On Tue, Mar 22, 2011 at 12:12 PM, Christopher W Ryan
> <cryan_at_binghamton.edu> wrote:
>> I have a dataframe that looks like this:
>>
>>  > str(chr)
>> 'data.frame':   84 obs. of  7 variables:
>>  $ county: Factor w/ 3 levels "Broome","Nassau",..: 3 3 3 3 3 3 3 3 3 3
>> ...
>>  $ item  : Factor w/ 28 levels "Access to healthy foods",..: 21 19 20
>> 18 16 3 2 6 17 8 ...
>>  $ value : num  8644 15 3.5 3.9 7.7 ...
>>  $ low   : num  7897 9 2.5 2.6 7 ...
>>  $ high  : num  9390 22 4.5 5.2 8.4 37 30 23 24 101 ...
>>  $ target: num  5034 11 2.7 2.6 6.1 ...
>>  $ nys   : num  6099 16 3.5 3.3 8 ...
>>
>>> head(chr)
>>    county                      item  value    low   high target    nys
>> 1 Sullivan           Premature death 8644.0 7897.0 9390.0 5034.0 6099.0
>> 2 Sullivan       Poor or fair health   15.0    9.0   22.0   11.0   16.0
>> 3 Sullivan Poor physical health days    3.5    2.5    4.5    2.7    3.5
>> 4 Sullivan   Poor mental health days    3.9    2.6    5.2    2.6    3.3
>> 5 Sullivan           Low birthweight    7.7    7.0    8.4    6.1    8.0
>> 6 Sullivan             Adult smoking   29.0   22.0   37.0   15.0   20.0
>>
>> I'd like to graph high and low for "Premature death" for each of the
>> three counties, with 3 vertical line segments, one connecting those
>> two points for each county.  I can get the two points for each county:
>>
>>>xyplot(low+high ~ county, data=subset(chr, item=="Premature death"))
>>
>> but I have not yet been able to figure out how to draw the 3 vertical
>> line segments. Been struggling to understand panel functions, but no
>> success so far. I'd be grateful for any advice.
>>
>> Thanks.
>>
>> --Chris Ryan
>> SUNY Upstate Medical University
>> Clinical Campus at Binghamton
>>
>> ______________________________________________
>> 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.
>>
>
>
>
> --
> Bert Gunter
> Genentech Nonclinical Biostatistics
>
> ______________________________________________
> 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.
>



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. Received on Wed 23 Mar 2011 - 00:11:08 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 23 Mar 2011 - 06:40:23 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive