[R] ploting a comparison of two scores, including the labels in the plot

Greg Snow Greg.Snow at intermountainmail.org
Mon Nov 5 18:51:08 CET 2007


Does the following do what you want (or at least start you in the correct direction)?

mydata <- data.frame( job=c("Ambassadör","Läkare","Domare",      
"Professor","Advokat","Pilot","Verkställande direktör","Forskare",
"Civilingenjör","Statsråd"), SAMHM= c(8.32, 8.15, 8.14, 8.13, 7.95,
 7.81, 7.78, 7.60, 7.47, 7.41),    INDM= c( 7.2771, 8.1029, 7.5965,
 7.5618, 7.1876, 7.4380, 6.8361, 7.6630, 6.8802, 6.3916))

     
tmp <- c(rbind( mydata$SAMHM, mydata$INDM, NA ))
tmp2 <- rep( c(1,2,NA), nrow(mydata) )

plot(tmp2, tmp, type='b', xlim=c(0,3), xlab='', ylab='rating')
text(0.9, mydata$SAMHM, mydata$job, adj=1, cex=0.75)
text(2.1, mydata$INDM, mydata$job, adj=0, cex=0.75)




-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at intermountainmail.org
(801) 408-8111
 
 

> -----Original Message-----
> From: r-help-bounces at r-project.org 
> [mailto:r-help-bounces at r-project.org] On Behalf Of Hans Ekbrand
> Sent: Thursday, November 01, 2007 7:13 AM
> To: r-help at r-project.org
> Subject: [R] ploting a comparison of two scores,including the 
> labels in the plot
> 
> Hello r-help!
> 
> I have data with two kind of ratings on status of 100 
> occupations. The first kind of rating is on the percieved 
> "objective" status that these occupations have in society at 
> large, and the second kind or rating is on the status that 
> the respondents think that these occuption *should* have.
> 
> The ratings were originally integer values in the rage 1-9, 
> but in the current data, I use their mean values.
> 
> Here is an printout for the first 10 occupations: (the 
> occupation names are in swedish)
> 
> > data.frame(myobj[1:10, c("YRKE", "SAMHM", "INDM")], row.names = 
> > "YRKE")
>                           SAMHM   INDM
> Ambassadör                 8.32 7.2771
> Läkare ("doctor")          8.15 8.1029
> Domare ("judge")           8.14 7.5965
> Professor                  8.13 7.5618
> Advokat ("lawyer")         7.95 7.1876
> Pilot                      7.81 7.4380
> Verkställande direktör     7.78 6.8361
> Forskare ("scientist"      7.60 7.6630
> Civilingenjör ("engineer") 7.47 6.8802
> Statsråd ("minister")      7.41 6.3916
> > 
> 
> I would like to make a plot with two lists. The first list 
> should list the occupations ordered by "SAMHM" (as in the 
> printout above) and the values of SAMH. The linespacing in 
> this list should be increased by the difference in SAMH 
> between the the occupations (i.e. between "Ambassadör" and 
> "Läkare" (eng. "doctor") there should be a larger 
> linespaceing than between "Läkare" and "Domare" (eng. "judge")).
> 
> The second list should be like the first, but based on "INDM" 
> instead of "SAMH".
> 
> These two list should ideally be plotted side by side with 
> lines connecting each occuption.
> 
> Here is an ascii-art illustration of what I intend (excluding 
> the connecting lines, which are hard to draw with ascii :-)
> 
> --------------------------------------
> Ambassadör                 
> 
> Läkare ("doctor")          
> Domare ("judge")            
> Professor                  Läkare
> 
> Advokat ("lawyer")         
> 
> Pilot     
> Verkställande direktör     
> 
> Forskare ("scientist")     Forskare
>                            Domare
> Civilingenjör ("engineer") Professor
> Statsråd ("minister")      Pilot
>                            Ambassadör
>                            Advokat
> 
> 
>                            Civilingenjör
>                            Verkställande direktör
> 
> 
>                            Statsråd
> ----------------------------------------------
> 
> If printing strings (labels) with different linespacing turns 
> out to be problematic, another solution would be to print a 
> list of the occupations ordered by "SAMH", points of "SAMH" 
> values (with Y="SAMH"), points of "INDM" (with Y="INDM") and 
> a list of occupations ordered by "INDM", with a line for each 
> occupation connecting the labels with the points and the two 
> points that represents the occupation.
> 
> Since there are a lot of functions for ploting and I am new 
> to R, I would like advise on what packages/functions that 
> should be used to get what I want (if what I want is possible 
> to achieve with R, if it is not, then please let me know).
> 
> Sample code is, of course, also very much appreciated.
> 
> kind regards,
> 
> --
> Hans Ekbrand (http://sociologi.cjb.net) 
> <hans at sociologi.cjb.net> A. Because it breaks the logical 
> sequence of discussion Q. Why is top posting bad?
> 



More information about the R-help mailing list