I have a data set which contains two columns. The first column is a list of countries, and the second column contains their political risk ratings. I would like to create one large plot that contains 5 different sections, each with a scatter plot. To clarify, I have divided the countries into 5 groups. For each group (continent), I would like to have the name of the continent on the x-axis, and points representing countries and their risk rating on the y-axis. However, I want all 5 scatter plots to be in one large plot. What function should I use to do this? Also, is it possible to label each point? thanks for any help!
Caroline Nganga wrote:> I have a data set which contains two columns. The first column is a > list of countries, and the second column contains their political risk > ratings. I would like to create one large plot that contains 5 > different sections, each with a scatter plot. To clarify, I have > divided the countries into 5 groups. For each group (continent), I > would like to have the name of the continent on the x-axis, and points > representing countries and their risk rating on the y-axis. However, > I want all 5 scatter plots to be in one large plot. What function > should I use to do this? Also, is it possible to label each point? > thanks for any help! >Hi Caroline, If I understand your request, you might be able to use the axis.break function in the plotrix package. That is, you make one big plot with the points in five columns and then put gap style axis breaks between the columns. Here's a toy example: library(plotrix) prr.df<-data.frame(country=c("us","mx","ca","br","ar","pe", "ch","mn","in","nl","fr","es","na","mz","rw"), continent=c(1,1,1,2,2,2,3,3,3,4,4,4,5,5,5), prr=rnorm(15)+4) plot(prr.df$continent,prr.df$prr,main="Political risk ratings", xlim=c(0.7,5.3),xlab="Continent",ylab="Risk rating",type="n") text(prr.df$continent,prr.df$prr,prr.df$country) axis.break(1,1.5,style="gap") axis.break(1,2.5,style="gap") axis.break(1,3.5,style="gap") axis.break(1,4.5,style="gap") Jim
Does the following code do something like what you want (but with the built in data):> plot(as.integer(state.region), state.x77[,'Murder'],+ xaxt='n', xlim=c(0,5), col=as.integer(state.region))> axis(1, at=1:4, labels=levels(state.region)) > > oo <- order(order( as.integer(state.region), state.x77[,'Murder'] )) > > tmp.p <- rep( c(2,4), length=50 )[oo] > > text(as.integer(state.region), state.x77[,'Murder'], state.name,pos=tmp.p, + col=as.integer(state.region))>If that is not what you want, then maybe you could give us some more detail so we can better understand. Hope this helps, -- 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 stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Caroline Nganga > Sent: Tuesday, August 21, 2007 11:01 AM > To: r-help at stat.math.ethz.ch > Subject: [R] divided scatter plots > > I have a data set which contains two columns. The first > column is a list of countries, and the second column contains > their political risk ratings. I would like to create one > large plot that contains 5 different sections, each with a > scatter plot. To clarify, I have divided the countries into 5 > groups. For each group (continent), I would like to have the > name of the continent on the x-axis, and points representing > countries and their risk rating on the y-axis. However, I > want all 5 scatter plots to be in one large plot. What > function should I use to do this? Also, is it possible to > label each point? > thanks for any help! > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >
Possibly Parallel Threads
- Lattice equivalent of par(mfrow = )
- Error "singular gradient matrix at initial parameter estimates" in nls
- problem with lattice tiff or bitmap: character size and color
- Help : delete at random
- Seeking help for outomating regression (over columns) and storing selected output