space between bars of a group in ggplot2
Hi,
Keep your emails on the list, please.
here are some artificial data
dput(dat)
structure(list(x = c("a", "a", "a", "b", "b", "b"), y = c(1,
1, 1, 3, 3, 3), cond = c("x1", "x2", "x3", "y1", "y2", "y3")), row.names =
c(NA,
6L), class = "data.frame")
And possible result
hist <- ggplot(dat, aes(x=x, y=y, fill=cond, stat="identity"))
hist + geom_col(width=0.4, position = position_dodge(width=0.5))
You could change colour scheme
https://stackoverflow.com/questions/18229835/how-do-i-manually-set-geom-bar-fill-color-in-ggplot
hist + geom_col(width=0.4, position = position_dodge(width=0.5))+
scale_fill_manual(values=rep(c("red", "blue"), each=3))
Cheers
Petr
From: azam jaafari <azamjaafari at yahoo.com>
Sent: Wednesday, December 16, 2020 10:57 AM
To: PIKAL Petr <petr.pikal at precheza.cz>
Subject: Re: [R] space between bars of a group in ggplot2
Hi Petr
Thank you for reply. I used this link
(https://stackoverflow.com/questions/6085238/adding-space-between-bars-in-ggplot2)
for separating bars, but it doesnt work for my purpose. since I have same
levels for one group, with this code, the bars are connected together: as a
bar for one group. While I want to add some space between three bars belong to
one group.
I really appreciate if you can help me
Sincerely
Azam
On Tuesday, December 15, 2020, 4:11:16 PM GMT+3:30, PIKAL Petr
<petr.pikal at precheza.cz> wrote:
Hi Your code is not reproducible, however you could follow this advice. https://stackoverflow.com/questions/6085238/adding-space-between-bars-in-ggplot2 Cheers Petr
-----Original Message-----
From: R-help <mailto:r-help-bounces at r-project.org> On Behalf Of azam jaafari
via
R-help
Sent: Monday, December 14, 2020 9:16 PM
To: mailto:r-help at r-project.org
Subject: [R] space between bars of a group in ggplot2
Hello Dear
I want to make a barplot for groups with three repetitions and same values.
dataset is like this:
groups: a b
c
value: 1.2, 1.2, 1.2 2.5, 2.5,2.5
Condition: sat, sat, sat, unsat,unsat,unsat,
that bars fill based on "condition"
I used the below code:
data%>%ggplot(aes(x=factor(groups), y=value, fill=factor(condition),
group=condition)) +
geom_bar(olour="black",stat="identity", position = position_dodge(width =
0.8), width=0.7)+ scale_y_continuous(breaks=seq(0, 6.5, 1),limits=c(0,
6.5),expand=c(0,0))+ scale_x_discrete(expand=c(0.000001,0))+
theme( axis.line = element_line(colour = "darkblue",
size = 1, linetype = "solid"))+ labs(x = "group Code",
y = "Z") +
theme(panel.background = element_rect(fill = 'white'))+labs(fill =
"Condition")+
theme(axis.text.x = element_text(face='bold',size=8, color='black', angle =
90, vjust = 0.5)) +
theme(axis.text.y = element_text(face='bold', size=8, color='black'))
but it makes the connected bars (without any space between values) for each
group, while I want to add a space between bars for each value of each
group.
Thank you for helping
BestAzam
[[alternative HTML version deleted]]
______________________________________________ mailto:R-help at 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.
Adding space between bars in ggplot2 I'd like to add spaces between bars in ggplot2. This page offers one solution: http://www.streamreader.org/stats...