Hi,

I am new to R and this is probably a very basic question but I can’t seem to 
figure out a solution. I am creating a stacked ggplot with the following data 
and code:

PercentageData.csv looks like this:

decision
treatment
percentage
labtreatment
defect
0
53.49
COMMON
defect
1
78.00
ASYMMETRIC
defect
2
96.67
PRIVATE
coop
0
46.51
COMMON
coop
1
22.00
ASYMMETRIC
coop
2
3.33
PRIVATE

%Load data:

charts.data <- read.csv("PercentageData.csv”)

%create stacked ggplot

p4 <- ggplot() + geom_bar(aes(y = percentage, x = treatment, fill = decision), 
data = charts.data, stat="identity")

p4

%y-axis is percentage and x-axis is treatment, ordered 0, 1, 2

I’d like to have the treatment names be strings so that 0=“COMMON”, 
1=“ASYMMETRIC”, 2=“PRIVATE”. How do I assign names to the treatment variable? 

I’ve tried to just have a new variable, x=labtreatment, but then the order of 
my data is graphed alphabetical (and not what I am looking for); Asymmetric on 
the left, Common in the middle, then Private on the right. Is there an easy way 
to reorder this?

Thanks for any help!

Best,
Mary


        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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