Sorry to keep asking elementary questions......I appreciate the help.
I am trying to create a dotchart with the rows sorted according to the
values, rather than the labels. When I try
prof <- c('Accountant', 'Administrative assistant',
'Garment worker',
'Cook',
'Dentist', 'General practictioner', 'Graduate
student', 'High level
manager',
'Low level manager', 'Mechanical engineer',
'Mechanic',
'Minister/priest/rabbi',
'Nurse', 'Professor', 'Sales clerk', 'Server',
'Taxi driver')
mol <- c(34, 29, 27, 36, 20, 40, 35, 32, 30, 31, 30, 32, 37, 37, 27,
28, 36)
dotchart(mol, labels = prof, main = 'Dot chart', xlab = 'Meaning of
life score')
I get a dot chart sorted by the values of prof; what I'd like is one
sorted by values of mol.
I looked at the help file for dotchart, but did not see anything.
Thanks again in advance
Peter L. Flom, PhD
Assistant Director, Statistics and Data Analysis Core
Center for Drug Use and HIV Research
National Development and Research Institutes
71 W. 23rd St
www.peterflom.com
New York, NY 10010
(212) 845-4485 (voice)
(917) 438-0894 (fax)
This one is ugly, but works... molprof<-data.frame(mol,prof) molprof <- molprof[with(molprof,order(mol)), ] dotchart(molprof$mol, labels = as.character(molprof$prof), main = 'Dot chart', xlab = 'Meaning of life score') HTH Tito Le ven 05/09/2003 ? 18:30, Peter Flom a ?crit :> Sorry to keep asking elementary questions......I appreciate the help. > > I am trying to create a dotchart with the rows sorted according to the > values, rather than the labels. When I try > > prof <- c('Accountant', 'Administrative assistant', 'Garment worker', > 'Cook', > 'Dentist', 'General practictioner', 'Graduate student', 'High level > manager', > 'Low level manager', 'Mechanical engineer', 'Mechanic', > 'Minister/priest/rabbi', > 'Nurse', 'Professor', 'Sales clerk', 'Server', 'Taxi driver') > mol <- c(34, 29, 27, 36, 20, 40, 35, 32, 30, 31, 30, 32, 37, 37, 27, > 28, 36) > > dotchart(mol, labels = prof, main = 'Dot chart', xlab = 'Meaning of > life score') > > I get a dot chart sorted by the values of prof; what I'd like is one > sorted by values of mol. > > I looked at the help file for dotchart, but did not see anything. > > Thanks again in advance > > Peter L. Flom, PhD > Assistant Director, Statistics and Data Analysis Core > Center for Drug Use and HIV Research > National Development and Research Institutes > 71 W. 23rd St > www.peterflom.com > New York, NY 10010 > (212) 845-4485 (voice) > (917) 438-0894 (fax) > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help-- L. Tito de Morais UR RAP IRD de Dakar BP 1386 Dakar S?n?gal T?l.: + 221 849 33 31 Fax: +221 832 16 75 Courriel: tito at ird.sn
Hi Peter, Dotchart plots the points in the order that it receives them - to plot them in order of increasing mol, you need to sort mol first. To make sure you keep the right prof associated to the right mol, I'd use names to connect the two first (this also means you don't need to provide an explicit labels vectors to dotchart) eg. names(mol) <- prof dotchart(sort(mol)) HTH, Hadley ------------------------------------------------- This mail sent through IMP: http://horde.org/imp/
On 5 Sep 2003 at 14:30, Peter Flom wrote:
prof <- c('Accountant', 'Administrative assistant',
'Garment worker',
'Cook',
'Dentist', 'General practictioner', 'Graduate
student',
'High level manager',
'Low level manager', 'Mechanical engineer',
'Mechanic',
'Minister/priest/rabbi',
'Nurse', 'Professor', 'Sales clerk',
'Server', 'Taxi driver')
mol <- c(34, 29, 27, 36, 20, 40, 35, 32, 30, 31, 30, 32, 37, 37, 27,
28, 36)
o <- order(mol)
mol <- mol[o]
prof <- prof[o]
dotchart(mol, labels = prof, main = 'Dot chart',
xlab = 'Meaning of life score')
Works for me.
Kjetil Halvorsen
> Sorry to keep asking elementary questions......I appreciate the help.
>
> I am trying to create a dotchart with the rows sorted according to the
> values, rather than the labels. When I try
>
> prof <- c('Accountant', 'Administrative assistant',
'Garment worker',
> 'Cook',
> 'Dentist', 'General practictioner', 'Graduate
student', 'High level
> manager',
> 'Low level manager', 'Mechanical engineer',
'Mechanic',
> 'Minister/priest/rabbi',
> 'Nurse', 'Professor', 'Sales clerk',
'Server', 'Taxi driver')
> mol <- c(34, 29, 27, 36, 20, 40, 35, 32, 30, 31, 30, 32, 37, 37, 27,
> 28, 36)
>
> dotchart(mol, labels = prof, main = 'Dot chart', xlab =
'Meaning of
> life score')
>
> I get a dot chart sorted by the values of prof; what I'd like is one
> sorted by values of mol.
>
> I looked at the help file for dotchart, but did not see anything.
>
> Thanks again in advance
>
> Peter L. Flom, PhD
> Assistant Director, Statistics and Data Analysis Core
> Center for Drug Use and HIV Research
> National Development and Research Institutes
> 71 W. 23rd St
> www.peterflom.com
> New York, NY 10010
> (212) 845-4485 (voice)
> (917) 438-0894 (fax)
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help