[R] dotchart for matrix data

Peter Ehlers ehlers at ucalgary.ca
Sat Dec 18 21:54:11 CET 2010


On 2010-12-18 10:27, e-letter wrote:
> On 18/12/2010, Peter Ehlers<ehlers at ucalgary.ca>  wrote:
>> On 2010-12-18 07:50, e-letter wrote:
>>>> Ben Bolker
>>>> Sat, 18 Dec 2010 07:07:24 -0800
>>
>> [... snip ...]
>>
>>> I am trying to create a chart like this
>>> (http://www.b-eye-network.com/images/content/Fig4_3.jpg); so this is
>>> not possible using R?
>>
>> That looks an awful lot like what lattice's dotplot would
>> produce. So: have you tried dotplot() as Ben has suggested?
>>
>
> For the benefit of other novices, this is what I did (gnu/linux):
>
> sign-in to a command terminal as root
> start R
> install.packages("reshape2")
>
> In another terminal as normal user
>
> require(reshape2)
> mdot<-melt(testdot)
> dotplot(value~category,groups=variable,data=mdot)
>
> The resultant graph shows the categories on the abscissa and there
> does not seem to be a way of selecting two columns from the original
> matrix. It is not like the graph cited in the hyperlink quoted above,
> but at least I have successfully followed instructions!

It seems to me that you're getting exactly the plot referred
to by the link, except that you have a factor with 4 levels, not 2.

>
> I changed the axes with the command:
>
> dotplot(category~value,groups=variable,data=mdot)
>
> I believe there is a command to select only certain rows of data which
> I think will achieve the desired graph, if unable I'll ask again, so
> thank you all.

See if the 'subset=' argument works for you:

  dotplot(category ~ value, groups = variable, data = mdot,
          subset = {variable %in% c("values1", "values2")},
          pch = c(1,3), cex = 1.5)

Peter Ehlers



More information about the R-help mailing list