Hi everyone, i?m trying to graphically display distributions with r and i?m working with makrodata from the WVS. the command i?m using is> plot (Makrodata$v11, Makrodata$v12, xlab="Democracy Score Economist", > ylab= share religious people")i?m having an additional variable that identifies respectively labels the cases with its country name. how can i implement that variable, so it identifies the various cases in the scatterplot and looks like the spss screenshot i posted below? <http://r.789695.n4.nabble.com/file/n4650650/Unbenannt.gif> thanks in advance! -- View this message in context: http://r.789695.n4.nabble.com/How-to-Label-Cases-in-Scatterplots-tp4650650.html Sent from the R help mailing list archive at Nabble.com.
Johannes, This will get you started tmp <- data.frame(x=rnorm(10), y=rnorm(10, 1000, 100), txt=letters[1:10]) plot(y ~ x, data=tmp) text(x=tmp$x+.05, y=tmp$y-20, labels=tmp$txt) rect(tmp$x-.05, tmp$y-25, tmp$x+.1, tmp$y-10) Rich You will probably need to use the xlim and ylim arguments on the plot function call. You will need to experiment with the constant adjustments on the text and rect calls. You might need vector adjustments rather than scalars on those calls. On Sat, Nov 24, 2012 at 11:04 AM, john55 <johannesm67@gmail.com> wrote:> Hi everyone, > > i´m trying to graphically display distributions with r and i´m working with > makrodata from the WVS. > > the command i´m using is > > > plot (Makrodata$v11, Makrodata$v12, xlab="Democracy Score Economist", > > ylab= share religious people") > > > i´m having an additional variable that identifies respectively labels the > cases with its country name. > how can i implement that variable, so it identifies the various cases in > the > scatterplot and looks like the spss screenshot i posted below? > > <http://r.789695.n4.nabble.com/file/n4650650/Unbenannt.gif> > > thanks in advance! > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/How-to-Label-Cases-in-Scatterplots-tp4650650.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@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. >[[alternative HTML version deleted]]
On 11/25/2012 03:04 AM, john55 wrote:> Hi everyone, > > i?m trying to graphically display distributions with r and i?m working with > makrodata from the WVS. > > the command i?m using is > >> plot (Makrodata$v11, Makrodata$v12, xlab="Democracy Score Economist", >> ylab= share religious people") > > > i?m having an additional variable that identifies respectively labels the > cases with its country name. > how can i implement that variable, so it identifies the various cases in the > scatterplot and looks like the spss screenshot i posted below? > > <http://r.789695.n4.nabble.com/file/n4650650/Unbenannt.gif> >Hi john55, This looks like thigmophobe.labels (plotrix), although it would be hard to avoid label overlapping with points that crowded. Jim
You could use something like this: #Generate 26 simulated data points y=rnorm(26) x=1:26 your.labels=letters #Plot data plot(x, y, xlim=c(min(x), max(x)+.25), ylim=c(min(y), max(y)+.25)) #Label points text(x+.15, y+.15, your.labels) You could also use the textxy function in the calibrate package as show here: http://www.r-bloggers.com/r-tutorial-series-labeling-data-points-on-a-plot/. ________________________________ From: john55 <johannesm67@gmail.com> To: r-help@r-project.org Sent: Saturday, November 24, 2012 11:04 AM Subject: [R] How to Label Cases in Scatterplots? Hi everyone, i´m trying to graphically display distributions with r and i´m working with makrodata from the WVS. the command i´m using is> plot (Makrodata$v11, Makrodata$v12, xlab="Democracy Score Economist", > ylab= share religious people")i´m having an additional variable that identifies respectively labels the cases with its country name. how can i implement that variable, so it identifies the various cases in the scatterplot and looks like the spss screenshot i posted below? <http://r.789695.n4.nabble.com/file/n4650650/Unbenannt.gif> thanks in advance! -- View this message in context: http://r.789695.n4.nabble.com/How-to-Label-Cases-in-Scatterplots-tp4650650.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@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. [[alternative HTML version deleted]]