[R] plotting a dataset with median 0

Marc Schwartz marc_schwartz at me.com
Sat Jun 5 18:14:46 CEST 2010


On Jun 5, 2010, at 9:08 AM, Georg Ehret wrote:

> Thank you, this is partially hepful Jim,
> my data are in 3 categories on the x-axis. Does anyone know of a method of
> plotting values identical on the y-axis distributed (adjacent to each other
> - piled up) on the x-axis?
> 
> 
> On Sat, Jun 5, 2010 at 12:00 PM, Jim Lemon <jim at bitwrit.com.au> wrote:
> 
>> On 06/05/2010 07:35 AM, Georg Ehret wrote:
>> 
>>> Dear R community,
>>>      I am working on a dataset that has median 0 (due to many "0"
>>> entries)
>>> for my principal variable of interest (40 entries in total). I would like
>>> to
>>> plot a graph of this variable to show it visually, but have a hard time:
>>> boxplots are not informative (because median 0). Conventional scatterplots
>>> are neither. Is there a good way to do this (e.g. plotting the "0" values
>>> with a jitter or something else...)?
>>> 
>>> Hi Georg,
>> Depending upon what you are plotting it against, count.overplot in the
>> plotrix package might do some good.
>> 
>> Jim


Georg,

Strictly speaking, a barplot() with 'beside = TRUE' might be helpful, but the offsetting nature of the bars can actually impede the interpretation the plot. 

A barchart() in lattice would enable you to create separate barplots, one for each category per 'panel'. This can also be done using par("mfrow" = c(3, 1)) in base graphics, where you would end up with three barplot()s, vertically aligned over each other. You would just have to be sure to explicitly define the x and y axis axis limits appropriately, so that these are consistent across the three plots, to aid in the visual comparison. See ?par for more information.

Both of the above, presume that you are looking at discrete counts on the y axis and not a continuous distribution.

The histogram() function in lattice might be another approach, possibly with overlapping density plots, creating a histogram per group in each panel.

Overlapping density plots might make also sense. densityplot() in the lattice package would be one approach, as well as the sm.density.compare() function in the 'sm' CRAN package. An example of the latter is at the bottom of:

  http://www.statmethods.net/graphs/density.html

Examples of the lattice plots are at:

  http://bm2.genes.nig.ac.jp/RGM2/R_current/library/lattice/man/histogram.html

If you change the last densityplot() example to:

  library(lattice)
  densityplot( ~ height, groups = voice.part, data = singer, plot.points = FALSE)

you can get something similar to the overlapping density plots in the 'sm' package.

Food for thought.

HTH,

Marc Schwartz



More information about the R-help mailing list