Hans Ekbrand
2007-Nov-01 13:12 UTC
[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? -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Digital signature Url : https://stat.ethz.ch/pipermail/r-help/attachments/20071101/e2c9cdd9/attachment.bin
John Kane
2007-Nov-01 18:52 UTC
[R] ploting a comparison of two scores, including the labels in the plot
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. >
Greg Snow
2007-Nov-05 17:51 UTC
[R] ploting a comparison of two scores, including the labels in the plot
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? >