Hi:

order() simply returns the index vector that corresponds to the ordering,
not the
ordering per se. Besides, when you read in the data, Occupation is read in
as a
factor that will by default order the levels alphabetically. If you want a
different
ordering, you can redefine the factor; e.g.,

df$Occupation <- factor(df$Occupations, levels = c('Doctor', 'Engineer',
'Accountant'))

It appears that you want to do something like a bar chart. The code below is
one
way to do this with base graphics, but this is readily done in lattice and
ggplot2 as
well. I refer to your toy data below as df and use the given ordering for
occupation.

> str(df)
'data.frame':   3 obs. of  3 variables:
 $ Occupation      : Factor w/ 3 levels "Accountant","Doctor",..: 1 3 2
 $ American.Workers: int  12 45 50
 $ Foreign.Workers : int  2 54 37

# Create a matrix of frequencies, using occupation as the row names:
> m <- as.matrix(df[, -1])
> rownames(m) <- df[, 1]
> m
           American.Workers Foreign.Workers
Accountant               12               2
Engineer                 45              54
Doctor                   50              37

# Create a bar chart (this one is side-by-side, the default (beside = FALSE)
# will stack instead)
> barplot(t(m), beside = TRUE, col = c('blue', 'red'))
> box()
# Add a legend
> legnames <- c('American', 'Foreign')
# Use the mouse to locate the legend on the graphics surface
> legend(locator(1), legend = legnames, fill = c('blue', 'red'))

HTH,
Dennis

On Mon, Mar 1, 2010 at 6:53 PM, cosinenonqua <sergeygoder@gmail.com> 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.
> --
> View this message in context:
> http://n4.nabble.com/Keeping-the-order-of-data-set-when-plotting-tp1574535p1574535.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]]

