Hi,
I am new in the forum and I have an issue with a bar graph.
This is my graph command :
reshape long Mysk, i(Email) j(question)
encode Mysk, gen(Mysk_reshaped)
label define catlbl 1 "Very Appropriate" 2 "Appropriate" 3 "Somewhat Appropriate" ///
4 "Somewhat Inappropriate" 5 "Inappropriate" 6 "Very Inappropriate"
label values Mysk_reshaped catlbl
graph bar (percent), over(question, gap(2) label(labsize(small)) relabel(1 "PN" 2 "SN" 3 "csPN")) over(Mysk_reshaped, gap(50) label(angle(45) labsize(small))) ascategory ytitle("Percent of respondents", size(small)) title("Distribution of responses by category", size(medsmall)) legend(order(1 "PN" 2 "SN" 3 "csPN") size(small) position(6)) bar(1, fcolor(blue) lcolor(black)) bar(2, fcolor(red) lcolor(black)) bar(3, fcolor(green) lcolor(black))
The problem is that I would like the bars to have different color by "question", so the bar PN to be red (for example), the bar SN to be black and the bar csPN to be green. If I run that command however the result is the one attached: all bars are blue. I have tried to ask AI but I couldn't find a solution, so I am trying here if anyone could help me.
Thank you very much in advance.
best,
Sarah
I am new in the forum and I have an issue with a bar graph.
This is my graph command :
reshape long Mysk, i(Email) j(question)
encode Mysk, gen(Mysk_reshaped)
label define catlbl 1 "Very Appropriate" 2 "Appropriate" 3 "Somewhat Appropriate" ///
4 "Somewhat Inappropriate" 5 "Inappropriate" 6 "Very Inappropriate"
label values Mysk_reshaped catlbl
graph bar (percent), over(question, gap(2) label(labsize(small)) relabel(1 "PN" 2 "SN" 3 "csPN")) over(Mysk_reshaped, gap(50) label(angle(45) labsize(small))) ascategory ytitle("Percent of respondents", size(small)) title("Distribution of responses by category", size(medsmall)) legend(order(1 "PN" 2 "SN" 3 "csPN") size(small) position(6)) bar(1, fcolor(blue) lcolor(black)) bar(2, fcolor(red) lcolor(black)) bar(3, fcolor(green) lcolor(black))
The problem is that I would like the bars to have different color by "question", so the bar PN to be red (for example), the bar SN to be black and the bar csPN to be green. If I run that command however the result is the one attached: all bars are blue. I have tried to ask AI but I couldn't find a solution, so I am trying here if anyone could help me.
Thank you very much in advance.
best,
Sarah

Comment