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

John Kane jrkrideau at yahoo.ca
Thu Nov 1 19:52:08 CET 2007


I gave it a try with conventional plot and it does not
look easy to get a good result.

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

status <- read.table(textConnection(x), header=TRUE)
xx1 <- c(rep(1,10))
xx2 <- c(rep(2,10))


plot(xx1, status[,2], xaxt='s', yaxt='s',
xlim=c(.5,2.5),
         ylim=c(min(status[,3]),max(status[,2])),
type='p', xlab="", ylab="")
points(xx2,status[,3])
segments(xx1,status[,2],xx2,status[,3])
text(xx1-.1,status[,2], labels=status[,1], cex=.6)
text(xx2+.1, status[,3], labels=status[,1], cex=.6)

--- Hans Ekbrand <hans.ekbrand at gmail.com> wrote:

> 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?
> > ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained,
> reproducible code.
>



More information about the R-help mailing list