[R] Keeping the order of data set when plotting

Jim Lemon jim at bitwrit.com.au
Tue Mar 2 08:26:07 CET 2010


On 03/02/2010 01:53 PM, cosinenonqua wrote:
>
> I have a data frame with 3 columns and I want to order the entire list by one
> column and then plot. I used order() and it does order the data set but when
> I plot it is as if the set is as it was originally. I also can't figure out
> how to plot two sets of data on the same graph. I have,
>
> Occupation		American.Workers	Foreign.Workers
> Accountant		12				2
> Engineer		45				54
> Doctor		50				37
>
> I want to be able to order American.Workers and then
> plot(Occupation,American.Workers) and plot(Occupation,Foreign.Workers) on
> the same graph.
Hi cosinenonqua,
This seems to do what you are asking, but you might not want this sort 
of plot:

plot(cosinenonqua$American.Workers,col=2,xaxt="n",ylim=c(0,55))
points(cosinenonqua$Foreign.Workers,col=4)
axis(1,at=1:3,labels=cosinenonqua$Occupation)
legend(1.7,30,c("American","Foreign"),col=c(2,4),pch=1)

Jim



More information about the R-help mailing list