Indeed, it helped - thank you, Bill.
And now - how could I now avoid the reversal on my axis with att_levels?
Currently it starts with the last one being the first one on the graph and
ends with the first one...


On Wed, Oct 30, 2013 at 12:04 PM, William Dunlap <wdun...@tibco.com> wrote:

> Try making att_levels (or att.levels, whatever you really call it)
> into a factor with the levels in the order you like.  E.g.,
>     aes(x = factor(att_levels, levels=unique(att_levels)), y = WTP)
> instead of
>     aes(x = att_levels, y = WTP)
>
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com
>
>
> > -----Original Message-----
> > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
> On Behalf
> > Of Dimitri Liakhovitski
> > Sent: Wednesday, October 30, 2013 7:35 AM
> > To: r-help
> > Subject: [R] ggplot2 question: keeping the order as in the input data
> >
> > Hello!
> >
> > I am using ggplot2 (see the code below) to plot the data in 'myplotdata'.
> > The first column of 'myplotdata' is called "att.levels" and contains
> > strings; the second column is called "WTP" and contains numeric values.
> > Notice - I use 'coord.flip()'
> >
> > The command aes(x=att_levels, y=WTP), if I understand correctly, sorts
> > things alphabetically based on the column 'att_levels'.
> > Question 1: How can I reverse the order for x in the plot (also
> > alphabetically but in the opposite direction)?
> > Question 2: How can I just have exactly the same order as in the object
> > 'myplotdata'?
> >
> > Thanks a lot!
> >
> > ggplot(myplotdata, aes(x=att_levels, y=WTP)) +
> >                 geom_bar(stat="identity",fill="dark
> orange",colour="black",
> > alpha = 1,position = "identity") +
> >
> >
> geom_text(aes(label=WTP),colour="black",size=4,hjust=1.1,position='dodge') +
> >                 coord_flip() +
> >                 xlab("") +
> >                 ylab("")
> >
> >
> >
> >
> > --
> > Dimitri Liakhovitski
> >
> >       [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > 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.
>



-- 
Dimitri Liakhovitski

        [[alternative HTML version deleted]]

______________________________________________
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.

Reply via email to