[R] dotchart for matrix data
inpost at gmail.com
Sat Dec 18 16:27:12 CET 2010
On 18/12/2010, David Winsemius <dwinsemius at comcast.net> wrote:
> On Dec 18, 2010, at 7:01 AM, e-letter wrote:
>> I am trying to use the function dotchart. The data is:
>> category values1 values2 values3 values4
>> 1 a 10 27 56 709
>> 2 b 4 46 47 208
>> 3 c 5 17 18 109
>> 4 d 6 50 49 308
>> The following error occurs
>> Error in dotchart(testdot, labels = testdot[, 1], groups = testdot[,
>> 2]) :
>> 'x' must be a numeric vector or matrix
>> According to my understanding (clearly wrong!) of the documentation
>> for dotchart (accessed from the manual in section 'graphics'), columns
>> of data can be selected by 'groups' for subsequent plotting.
> The misunderstanding is in how you see the grouping information versus
> how R expects it. R generally expects such data in what is called
> "long" format, i.e. there will be one values columns and a category
> column. There are various ways to change the arrangement of your data.
> The function stack(), the function reshape(), or probably most
> commonly the function melt from reshape2 being the typical chosen
Reshape and melt are not installed (version251) so for this task
manual rearrangement data is easier.
Loading required package: reshape
there is no package called 'reshape' in: library(package, lib.loc =
lib.loc, character.only = TRUE, logical = TRUE,
Error in library(reshape) : there is no package called 'reshape'
Error: could not find function "melt"
However before doing so why this is relevant because of the
alternative creation objects 'testdot1'. Aren't these objects
suitable, since a (undesireable) graph was produced?
>> objective is to be able to create a dot chart where each row is
>> labelled according to the row names in the 'category' column and two
>> columns can be selected, e.g. 'values1' and 'values2'. Then I tried:
> See if this is more to your liking:
> require(reshape) # I'm not sure why I have reshape_0.8.3 rather than
> reshape2 loaded
> # I'm pretty sure Hadley would prefer that people
> use pkg:reshape2
> mdot <- melt(dot)
> dotchart(mdot$value, groups=mdot$category, labels=mdot$variable)
> # OR more readable
> with(mdot, dotchart(value, groups=category, labels=variable) )
> I'm not sure I got the roles of "values" and "category" correct, but
> it should be a simple matter to switch them in the dotcghart call if
> that is your pleasuRe.
I don't have dotcghart either.
More information about the R-help